home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libprintui
/
PrintBox.c.z
/
PrintBox.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
176KB
|
5,996 lines
/**************************************************************************
* *
* Copyright (c) 1991 Silicon Graphics, Inc. *
* All Rights Reserved *
* *
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
* *
* The copyright notice above does not evidence any actual of intended *
* publication of such source code, and is an unpublished work by Silicon *
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
* the property of Silicon Graphics, Inc. Any use, duplication or *
* disclosure not specifically authorized by Silicon Graphics is strictly *
* prohibited. *
* *
* RESTRICTED RIGHTS LEGEND: *
* *
* Use, duplication or disclosure by the Government is subject to *
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
* Technical Data and Computer Software clause at DFARS 52.227-7013, *
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
* Supplement. Unpublished - rights reserved under the Copyright Laws of *
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
* Shoreline Blvd., Mountain View, CA 94039-7311 *
**************************************************************************
*
* File: PrintBox.c
*
* Description: Primary implementation file for the PrintBox printing
* GUI widget.
*
**************************************************************************/
#ident "$Revision: 1.17 $"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <bstring.h>
#include <pwd.h>
#include <msgs/uxsgiimpr.h>
#include <X11/StringDefs.h>
#include <X11/cursorfont.h>
#include <Xm/XmP.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>
#include <Xm/List.h>
#include <Xm/TextF.h>
#include <Xm/ScrolledW.h>
#include <Xm/ToggleB.h>
#include <Xm/BulletinB.h>
#include <Xm/DialogS.h>
#include <Xm/Separator.h>
#include <Xm/ArrowB.h>
#include <Xm/SelectioB.h>
#include <Sgm/PrintBoxP.h>
#include "PuiI.h"
/* Misc defines */
#define MAX_PNAME 14 /* Max # chars in a printer name */
#define MAX_FORMALNAME 40
#define MAX_LINE 1024 /* General buffer size */
/* Cursor state enum */
typedef enum { PuiCursorBusy, PuiCursorNormal } PuiCursorState;
/* Class part field macros */
#define XPOS(w) (w)->core.x
#define YPOS(w) (w)->core.y
#define WIDTH(w) (w)->core.width
#define HEIGHT(w) (w)->core.height
#define BWIDTH(w) (w)->core.border_width
#define MARGIN_WIDTH(w) (w)->bulletin_board.margin_width
#define MARGIN_HEIGHT(w) (w)->bulletin_board.margin_height
#define HORIZ_SPACING(w) MARGIN_WIDTH(w)
#define VERT_SPACING(w) MARGIN_HEIGHT(w)
/* Geometry request macros */
#define REQUEST_MODE(req,mask) (req->request_mode & (mask))
/* Resource offset macro */
#define offset(field) XtOffsetOf(PuiPrintBoxRec, field)
/* Widget method declarations */
static void ClassInitialize(void);
static void Initialize(Widget, Widget, ArgList, Cardinal*);
static void Destroy(Widget);
static void ChangeManaged(Widget);
static XtGeometryResult GeometryManager(Widget, XtWidgetGeometry*,
XtWidgetGeometry*);
static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry*,
XtWidgetGeometry*);
static void Resize(Widget);
static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal*);
static void InsertChild(Widget);
static void DeleteChild(Widget);
/* Widget private method declarations */
/* UI creation functions */
static void CreateActionArea(PuiPrintBoxWidget);
static void CreateControlArea(PuiPrintBoxWidget);
static void CreateOptionArea(PuiPrintBoxPart*, Widget);
static Widget CreateSaveDialog(PuiPrintBoxWidget);
/* UI handling functions */
static void UpdateLabel(Widget, String, XmString*);
static void InitTextFieldColors(PuiPrintBoxWidget);
static void SetTextFieldSensitivity(PuiPrintBoxPart*, Widget, Boolean);
static void SetCursor(PuiPrintBoxWidget, PuiCursorState);
/* General functions */
static void SetFilenames(PuiPrintBoxPart*);
static void SetPrinter(PuiPrintBoxPart*);
static int SetPrinterList(PuiPrintBoxWidget);
static int FindPrinter(PuiPrintBoxPart*, char*);
static void ClearPrinterOptions(PuiPrintBoxPart*);
static void AddPrinterOptions(PuiPrintBoxPart*, char*);
static void SetStringValue(char**, char**, char**);
static void HandleError(PuiPrintBoxWidget, int);
static void FreePrinterList(SLPrinterStruct*, int);
static SLPrinterStruct* CopyPrinterList(SLPrinterStruct*, int);
static void InitCallback(PuiPrintBoxCallbackStruct*);
/* Widget layout functions */
static void SetOptionsSize(PuiPrintBoxPart*);
static void SetPrinterListSize(PuiPrintBoxPart*);
static void SetActionAreaSize(PuiPrintBoxPart*);
static void DoLayout(PuiPrintBoxWidget);
static void CalculateMySize(PuiPrintBoxWidget, int*, int*);
/* Settings file handling functions */
static void ReadSpoolerOptionsFile(PuiPrintBoxPart*);
static int WriteSpoolerOptionsFile(PuiPrintBoxWidget);
static char* ReadPrinterOptionsFile(char*);
static void UpdatePrinterOption(PuiPrintBoxWidget, PuiPrinterOption*);
static int WritePrinterOptionsFile(char*, char*, int);
/* Internal callback functions */
static void PrintSensitiveCB(Widget, XtPointer, XtPointer);
static void PrinterSelectedCB(Widget, XtPointer, XtPointer);
static void SubmitPrintJobCB(Widget, XtPointer, XtPointer);
static void DestroyParentCB(Widget, XtPointer, XtPointer);
static void UnmanageCB(Widget, XtPointer, XtPointer);
static void ActionAreaCB(Widget, XtPointer, XtPointer);
static void QueryForSaveCB(Widget, XtPointer, XtPointer);
static void SaveOptionsCB(Widget, XtPointer, XtPointer);
static void OptionButtonCB(Widget, XtPointer, XtPointer);
static void OptionDataCB(PuiOptionPanel*, XtPointer,
PuiOptionPanelCallbackStruct*);
static void OptionMappedCB(PuiOptionPanel*, XtPointer,
PuiOptionPanelCallbackStruct*);
static void OptionErrorCB(PuiOptionPanel*, XtPointer,
PuiOptionPanelCallbackStruct*);
static void OptionDeathCB(PuiOptionPanel*, XtPointer,
PuiOptionPanelCallbackStruct*);
/* Synthetic resource funtions */
static void SynthGetFilename(Widget, int, XtArgVal*);
static void SynthGetPrinter(Widget, int, XtArgVal*);
static void SynthGetLabel(Widget, int, XtArgVal*);
static void SynthGetButtonSpacing(Widget, int, XtArgVal*);
static void SynthGetVisibleCount(Widget, int, XtArgVal*);
/* Printing option functions */
/* Number of copies */
static void CreateOptionNumCopies(PuiPrintBoxPart*, Widget);
static void SetOptionNumCopies(PuiPrintBoxPart*);
static void GetOptionNumCopies(PuiPrintBoxPart*);
static void SynthGetOptionNumCopies(Widget, int, XtArgVal*);
/* Banner page */
static void CreateOptionBanner(PuiPrintBoxPart*, Widget);
static void SetOptionBanner(PuiPrintBoxPart*);
static void GetOptionBanner(PuiPrintBoxPart*);
static void SynthGetOptionBanner(Widget, int, XtArgVal*);
/* Job completion notification */
static void CreateOptionCompletion(PuiPrintBoxPart*, Widget);
static void SetOptionCompletion(PuiPrintBoxPart*);
static void GetOptionCompletion(PuiPrintBoxPart*);
static void SynthGetOptionCompletion(Widget, int, XtArgVal*);
/* Print file handling */
static void CreateOptionJobHandling(PuiPrintBoxPart*, Widget);
static void SetOptionJobHandling(PuiPrintBoxPart*);
static void GetOptionJobHandling(PuiPrintBoxPart*);
static void SynthGetOptionJobHandling(Widget, int, XtArgVal*);
/* Printer specific options */
static void CreateOptionPrinterSpecific(PuiPrintBoxPart*, Widget);
static void SetOptionPrinterSpecific(PuiPrintBoxPart*);
static void GetOptionPrinterSpecific(PuiPrintBoxPart*);
static void SynthGetOptionPrinterSpecific(Widget, int, XtArgVal*);
/* Printing option structure initialization */
static PuiPrintBoxOption option_list[] = {
{ /* Number of copies */
CreateOptionNumCopies,
SetOptionNumCopies,
GetOptionNumCopies,
SynthGetOptionNumCopies,
},
{ /* Banner page */
CreateOptionBanner,
SetOptionBanner,
GetOptionBanner,
SynthGetOptionBanner,
},
{ /* Job completion */
CreateOptionCompletion,
SetOptionCompletion,
GetOptionCompletion,
SynthGetOptionCompletion,
},
{ /* Job handling */
CreateOptionJobHandling,
SetOptionJobHandling,
GetOptionJobHandling,
SynthGetOptionJobHandling,
},
{ /* Printer specific options */
CreateOptionPrinterSpecific,
SetOptionPrinterSpecific,
GetOptionPrinterSpecific,
SynthGetOptionPrinterSpecific,
},
};
static int num_options = sizeof(option_list) / sizeof(PuiPrintBoxOption);
/* Widget synthetic resource list */
static XmSyntheticResource syn_resources[] = {
/* BASIC PRINT JOB INFO ------------------------------------------- */
/* Printer */
{
PuiNprinter, sizeof(String),
offset(printBox.res_printer),
SynthGetPrinter,
NULL
},
/* Print filename specified as a resource */
{
PuiNfilename, sizeof(String),
offset(printBox.res_filename),
SynthGetFilename,
NULL
},
/* LAYOUT INFO ---------------------------------------------------- */
/* Action area button spacing */
{
PuiNbuttonSpacing, sizeof(int),
offset(printBox.res_button_spacing),
SynthGetButtonSpacing,
NULL
},
/* Printer list visible item count */
{
PuiNlistVisibleItemCount, sizeof(int),
offset(printBox.res_vis_count),
SynthGetVisibleCount,
NULL
},
/* OPTION RESOURCES ----------------------------------------------- */
/* Number of copies */
{
PuiNnumCopies, sizeof(int),
offset(printBox.res_numcopies),
SynthGetOptionNumCopies,
NULL
},
/* Copy files */
{
PuiNcopy, sizeof(Boolean),
offset(printBox.res_copy),
SynthGetOptionJobHandling,
NULL
},
/* Mail on completion */
{
PuiNmail, sizeof(Boolean),
offset(printBox.res_mail),
SynthGetOptionCompletion,
NULL
},
/* Console message on completion */
{
PuiNmessage, sizeof(Boolean),
offset(printBox.res_message),
SynthGetOptionCompletion,
NULL
},
/* Job title */
{
PuiNjobTitle, sizeof(String),
offset(printBox.res_job_title),
SynthGetOptionBanner,
NULL
},
/* Printer specific options */
{
PuiNprinterOptions, sizeof(String),
offset(printBox.res_spec_opts),
SynthGetOptionPrinterSpecific,
NULL
},
/* UI LABELING ---------------------------------------------------- */
/* Print button label */
{
PuiNprintLabelString, sizeof(XmString),
offset(printBox.res_printb_label),
SynthGetLabel, NULL
},
/* User defined button 1 label */
{
PuiNuser1LabelString, sizeof(XmString),
offset(printBox.res_user1b_label),
SynthGetLabel, NULL
},
/* User defined button 2 label */
{
PuiNuser2LabelString, sizeof(XmString),
offset(printBox.res_user2b_label),
SynthGetLabel, NULL
},
/* User defined button 3 label */
{
PuiNuser3LabelString, sizeof(XmString),
offset(printBox.res_user3b_label),
SynthGetLabel, NULL
},
/* User defined button 4 label */
{
PuiNuser4LabelString, sizeof(XmString),
offset(printBox.res_user4b_label),
SynthGetLabel, NULL
},
/* Options button label */
{
PuiNoptionsbLabelString, sizeof(XmString),
offset(printBox.res_optionsb_label),
SynthGetLabel, NULL
},
/* Save button label */
{
PuiNsaveLabelString, sizeof(XmString),
offset(printBox.res_saveb_label),
SynthGetLabel, NULL
},
/* Cancel button label */
{
PuiNcancelLabelString, sizeof(XmString),
offset(printBox.res_cancelb_label),
SynthGetLabel, NULL
},
/* Help button label */
{
PuiNhelpLabelString, sizeof(XmString),
offset(printBox.res_helpb_label),
SynthGetLabel, NULL
},
/* Filename label */
{
PuiNfilenameLabelString, sizeof(XmString),
offset(printBox.res_files_label),
SynthGetLabel, NULL
},
/* Print list label */
{
PuiNprinterLabelString, sizeof(XmString),
offset(printBox.res_plist_label),
SynthGetLabel, NULL
},
/* Option list label */
{
PuiNoptionLabelString, sizeof(XmString),
offset(printBox.res_opts_label),
SynthGetLabel, NULL
},
/* Number of copies option label */
{
PuiNnumCopiesLabelString, sizeof(XmString),
offset(printBox.res_numcopies_label),
SynthGetLabel, NULL
},
/* Banner page title option label */
{
PuiNjobTitleLabelString, sizeof(XmString),
offset(printBox.res_title_label),
SynthGetLabel, NULL
},
/* Banner page default title option label */
{
PuiNjobDefTitleLabelString, sizeof(XmString),
offset(printBox.res_deftitle_label),
SynthGetLabel, NULL
},
/* Banner page user specified title option label */
{
PuiNjobSpecTitleLabelString, sizeof(XmString),
offset(printBox.res_spectitle_label),
SynthGetLabel, NULL
},
/* Job completion notification option label */
{
PuiNcompletionLabelString, sizeof(XmString),
offset(printBox.res_complete_label),
SynthGetLabel, NULL
},
/* Notify by mail option label */
{
PuiNmailLabelString, sizeof(XmString),
offset(printBox.res_complete_mail_label),
SynthGetLabel, NULL
},
/* Notify by console message option label */
{
PuiNmessageLabelString, sizeof(XmString),
offset(printBox.res_complete_mess_label),
SynthGetLabel, NULL
},
/* Print job handling option label */
{
PuiNhandlingLabelString, sizeof(XmString),
offset(printBox.res_handling_label),
SynthGetLabel, NULL
},
/* Handle by copying option label */
{
PuiNcopyJobLabelString, sizeof(XmString),
offset(printBox.res_handling_copy_label),
SynthGetLabel, NULL
},
/* Handle by linking option label */
{
PuiNlinkJobLabelString, sizeof(XmString),
offset(printBox.res_handling_link_label),
SynthGetLabel, NULL
},
/* Printer specific options label */
{
PuiNprinterSpecLabelString, sizeof(XmString),
offset(printBox.res_spec_options_label),
SynthGetLabel, NULL
},
/* Save dialog - title label */
{
PuiNsaveDlgTitleLabelString, sizeof(XmString),
offset(printBox.res_savedlg_title_label),
SynthGetLabel, NULL
},
/* Save dialog - Save button label */
{
PuiNsaveDlgSaveLabelString, sizeof(XmString),
offset(printBox.res_savedlg_saveb_label),
SynthGetLabel, NULL
},
/* Save dialog - Save for user button label */
{
PuiNsaveDlgUserLabelString, sizeof(XmString),
offset(printBox.res_savedlg_userb_label),
SynthGetLabel, NULL
},
/* Save dialog - Save for all users button label */
{
PuiNsaveDlgAllLabelString, sizeof(XmString),
offset(printBox.res_savedlg_allb_label),
SynthGetLabel, NULL
},
/* Save dialog - Cancel button label */
{
PuiNsaveDlgCancelLabelString, sizeof(XmString),
offset(printBox.res_savedlg_cancelb_label),
SynthGetLabel, NULL
},
/* Save dialog - message label */
{
PuiNsaveDlgMsgLabelString, sizeof(XmString),
offset(printBox.res_savedlg_msg_label),
SynthGetLabel, NULL
},
};
/* Widget resource list */
static XtResource resources[] = {
/* BASIC PRINT JOB INFO ------------------------------------------- */
/* Printer */
{
PuiNprinter, PuiCPrinter, XtRString, sizeof(String),
offset(printBox.res_printer), XtRImmediate, (XtPointer)DEF_PRINTER
},
/* Print job type (eg. filename, descriptor, buffer) */
{
PuiNjobType, PuiCJobType, XtRInt, sizeof(int),
offset(printBox.res_job_type), XtRImmediate, (XtPointer)DEF_JOB_TYPE
},
/* Print filename specified as a resource */
{
PuiNfilename, PuiCFilename, XtRString, sizeof(String),
offset(printBox.res_filename), XtRImmediate, (XtPointer)DEF_FILENAME
},
/* Print file descriptor */
{
PuiNfd, PuiCFd, XtRInt, sizeof(int),
offset(printBox.res_fd), XtRImmediate, (XtPointer)DEF_FD
},
/* Print buffer */
{
PuiNbuffer, PuiCBuffer, XtRPointer, sizeof(XtPointer),
offset(printBox.res_buffer), XtRImmediate, (XtPointer)DEF_BUFFER
},
/* Print buffer size */
{
PuiNbufSize, PuiCBufSize, XtRInt, sizeof(int),
offset(printBox.res_bufsize), XtRImmediate, (XtPointer)DEF_BUFSIZE
},
/* Printing policy */
{
PuiNprintingPolicy, PuiCPrintingPolicy,
PuiRPrintingPolicy, sizeof(int),
offset(printBox.res_print_policy), XtRImmediate,
(XtPointer)DEF_PRINT_POLICY
},
/* PRINTER INFO (read-only) --------------------------------------- */
/* Available printer list */
{
PuiNprinterList, PuiCPrinterList, XtRPointer, sizeof(XtPointer),
offset(printBox.res_printer_list), XtRImmediate, (XtPointer)NULL
},
/* Number of printers in available printer list */
{
PuiNnumPrinters, PuiCNumPrinters, XtRInt, sizeof(int),
offset(printBox.res_num_printers), XtRImmediate, (XtPointer)0
},
/* System default printer name */
{
PuiNdefPrinter, PuiCDefPrinter, XtRString, sizeof(String),
offset(printBox.res_default_printer), XtRImmediate, (XtPointer)NULL
},
/* LOOK AND FEEL INFO -------------------------------------------- */
/* Show filename entry */
{
PuiNshowFilename, PuiCShowFilename, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_fname), XtRImmediate, (XtPointer)DEF_SHOW_FNAME
},
/* Show options */
{
PuiNshowOptions, PuiCShowOptions, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_opts), XtRImmediate, (XtPointer)DEF_SHOW_OPTS
},
/* Show number of copies option */
{
PuiNshowNumCopies, PuiCShowNumCopies, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_numcopies), XtRImmediate,
(XtPointer)DEF_SHOW_NUMCOPIES
},
/* Show banner page title option */
{
PuiNshowBannerTitle, PuiCShowBannerTitle, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_bannertitle), XtRImmediate,
(XtPointer)DEF_SHOW_BANNERTITLE
},
/* Show completion notification option */
{
PuiNshowCompletion, PuiCShowCompletion, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_completion), XtRImmediate,
(XtPointer)DEF_SHOW_COMPLETION
},
/* Show job handling option */
{
PuiNshowHandling, PuiCShowHandling, XtRBoolean, sizeof(Boolean),
offset(printBox.res_show_handling), XtRImmediate,
(XtPointer)DEF_SHOW_HANDLING
},
/* Show printer specific options */
{
PuiNshowPrinterOptions, PuiCShowPrinterOptions, XtRBoolean,
sizeof(Boolean),
offset(printBox.res_show_printeroptions), XtRImmediate,
(XtPointer)DEF_SHOW_PRINTEROPTIONS
},
/* Show Options button */
{
PuiNshowOptionsButton, PuiCShowOptionsButton, XtRBoolean,
sizeof(Boolean), offset(printBox.res_show_optionsbutton), XtRImmediate,
(XtPointer)DEF_SHOW_OPTIONSBUTTON
},
/* Show Save button */
{
PuiNshowSaveButton, PuiCShowSaveButton, XtRBoolean,
sizeof(Boolean), offset(printBox.res_show_savebutton), XtRImmediate,
(XtPointer)DEF_SHOW_SAVEBUTTON
},
/* Action area button placement */
{
PuiNbuttonPlacement, PuiCButtonPlacement, PuiRButtonPlacement,
sizeof(int), offset(printBox.res_button_placement),
XtRImmediate, (XtPointer)DEF_BUTTON_PLACEMENT
},
/* Action area button spacing */
{
PuiNbuttonSpacing, PuiCButtonSpacing, XtRInt, sizeof(int),
offset(printBox.res_button_spacing),
XtRImmediate, (XtPointer)DEF_BUTTON_SPACING
},
/* Printer list visible item count */
{
PuiNlistVisibleItemCount, PuiCVisibleItemCount, XtRInt, sizeof(int),
offset(printBox.res_vis_count), XtRImmediate, (XtPointer)DEF_VIS_COUNT
},
/* Printer list printer font */
{
PuiNprinterFont, PuiCFont, XtRFontStruct,
sizeof(XFontStruct*), offset(printBox.res_printer_font), XtRString,
DEF_PRINTER_FONT
},
/* Printer list default printer font */
{
PuiNdefaultPrinterFont, PuiCFont, XtRFontStruct,
sizeof(XFontStruct*), offset(printBox.res_def_printer_font), XtRString,
DEF_DEFAULT_PRINTER_FONT
},
/* Busy Cursor */
{
PuiNbusyCursor, PuiCCursor, XtRCursor, sizeof(Cursor),
offset(printBox.res_busy_cursor), XtRString, DEF_BUSY_CURSOR
},
/* TEXT FIELD SENSITIVITY ---------------------------------------- */
/* Text field insensitive foreground color */
{
PuiNinsensitiveForeground, PuiCForeground, XtRPixel, sizeof(Pixel),
offset(printBox.tfield_insensitive.foreground), XtRString,
(XtPointer)DEF_INSENSITIVE_FORE
},
/* Text field insensitive background color */
{
PuiNinsensitiveBackground, PuiCBackground, XtRPixel, sizeof(Pixel),
offset(printBox.tfield_insensitive.background), XtRString,
(XtPointer)DEF_INSENSITIVE_BACK
},
/* Filename field sensitivity */
{
PuiNfilenameSensitive, PuiCSensitive, XtRBoolean, sizeof(Boolean),
offset(printBox.res_filename_sensitive), XtRImmediate, (XtPointer)True
},
/* Number of copies field sensitivity */
{
PuiNnumCopiesSensitive, PuiCSensitive, XtRBoolean, sizeof(Boolean),
offset(printBox.res_numcopies_sensitive), XtRImmediate, (XtPointer)True
},
/* Printer options field sensitivity */
{
PuiNprinterOptionsSensitive, PuiCSensitive, XtRBoolean, sizeof(Boolean),
offset(printBox.res_poptions_sensitive), XtRImmediate, (XtPointer)True
},
/* CALLBACKS ---------------------------------------------------- */
/* Print button callback */
{
PuiNprintCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_print_callback), XtRImmediate, (XtPointer)NULL
},
/* User1 button callback */
{
PuiNuser1Callback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_user1_callback), XtRImmediate, (XtPointer)NULL
},
/* User2 button callback */
{
PuiNuser2Callback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_user2_callback), XtRImmediate, (XtPointer)NULL
},
/* User3 button callback */
{
PuiNuser3Callback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_user3_callback), XtRImmediate, (XtPointer)NULL
},
/* User4 button callback */
{
PuiNuser4Callback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_user4_callback), XtRImmediate, (XtPointer)NULL
},
/* Save button callback */
{
PuiNsaveCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_save_callback), XtRImmediate, (XtPointer)NULL
},
/* Cancel button callback */
{
PuiNcancelCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_cancel_callback), XtRImmediate, (XtPointer)NULL
},
/* Help button callback */
{
PuiNhelpCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_help_callback), XtRImmediate, (XtPointer)NULL
},
/* Print job information callback */
{
PuiNjobInfoCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_jobinfo_callback), XtRImmediate, (XtPointer)NULL
},
/* Printer selection callback */
{
PuiNprinterSelectCallback, PuiCCallback, XtRCallback,
sizeof(XtCallbackList),
offset(printBox.res_pr_select_callback), XtRImmediate, (XtPointer)NULL
},
/* Printer action callback */
{
PuiNprinterActionCallback, PuiCCallback, XtRCallback,
sizeof(XtCallbackList),
offset(printBox.res_pr_action_callback), XtRImmediate, (XtPointer)NULL
},
/* Error callback */
{
PuiNerrorCallback, PuiCCallback, XtRCallback, sizeof(XtCallbackList),
offset(printBox.res_error_callback), XtRImmediate, (XtPointer)NULL
},
/* Option panel error callback */
{
PuiNoptionErrorCallback, PuiCCallback, XtRCallback,
sizeof(XtCallbackList),
offset(printBox.res_opt_error_callback), XtRImmediate, (XtPointer)NULL
},
/* UI LABELING -------------------------------------------------- */
/* Print button label */
{
PuiNprintLabelString, PuiCPrintLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_printb_label), XtRString,
(XtPointer)NULL
},
/* User defined button 1 label */
{
PuiNuser1LabelString, PuiCUser1LabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_user1b_label), XtRString,
(XtPointer)NULL
},
/* User defined button 2 label */
{
PuiNuser2LabelString, PuiCUser2LabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_user2b_label), XtRString,
(XtPointer)NULL
},
/* User defined button 3 label */
{
PuiNuser3LabelString, PuiCUser3LabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_user3b_label), XtRString,
(XtPointer)NULL
},
/* User defined button 4 label */
{
PuiNuser4LabelString, PuiCUser4LabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_user4b_label), XtRString,
(XtPointer)NULL
},
/* Options button label */
{
PuiNoptionsbLabelString, PuiCOptionsbLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_optionsb_label), XtRString,
(XtPointer)NULL
},
/* Save button label */
{
PuiNsaveLabelString, PuiCSaveLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_saveb_label), XtRString,
(XtPointer)NULL
},
/* Cancel button label */
{
PuiNcancelLabelString, PuiCCancelLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_cancelb_label), XtRString,
(XtPointer)NULL
},
/* Help button label */
{
PuiNhelpLabelString, PuiCHelpLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_helpb_label), XtRString,
(XtPointer)NULL
},
/* Filename label */
{
PuiNfilenameLabelString, PuiCFilenameLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_files_label), XtRString,
(XtPointer)NULL
},
/* Printer list label */
{
PuiNprinterLabelString, PuiCPrinterLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_plist_label), XtRString,
(XtPointer)NULL
},
/* Option list label */
{
PuiNoptionLabelString, PuiCOptionLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_opts_label), XtRString,
(XtPointer)NULL
},
/* Number of copies option label */
{
PuiNnumCopiesLabelString, PuiCNumCopiesLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_numcopies_label), XtRString,
(XtPointer)NULL
},
/* Banner page title option label */
{
PuiNjobTitleLabelString, PuiCJobTitleLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_title_label), XtRString,
(XtPointer)NULL
},
/* Banner page default title option label */
{
PuiNjobDefTitleLabelString, PuiCJobDefTitleLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_deftitle_label), XtRString,
(XtPointer)NULL
},
/* Banner page user specified title option label */
{
PuiNjobSpecTitleLabelString, PuiCJobSpecTitleLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_spectitle_label), XtRString,
(XtPointer)NULL
},
/* Job completion notification option label */
{
PuiNcompletionLabelString, PuiCCompletionLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_complete_label), XtRString,
(XtPointer)NULL
},
/* Notify by mail option label */
{
PuiNmailLabelString, PuiCMailLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_complete_mail_label), XtRString,
(XtPointer)NULL
},
/* Notify by console message option label */
{
PuiNmessageLabelString, PuiCMessageLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_complete_mess_label), XtRString,
(XtPointer)NULL
},
/* Print job handling option label */
{
PuiNhandlingLabelString, PuiCHandlingLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_handling_label), XtRString,
(XtPointer)NULL
},
/* Handle by copying option label */
{
PuiNcopyJobLabelString, PuiCCopyJobLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_handling_copy_label), XtRString,
(XtPointer)NULL
},
/* Handle by linking option label */
{
PuiNlinkJobLabelString, PuiCLinkJobLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_handling_link_label), XtRString,
(XtPointer)NULL
},
/* Printer specific options label */
{
PuiNprinterSpecLabelString, PuiCPrinterSpecLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_spec_options_label), XtRString,
(XtPointer)NULL
},
/* Save dialog - dialog title label */
{
PuiNsaveDlgTitleLabelString, PuiCSaveDlgTitleLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_title_label), XtRString,
(XtPointer)DEF_SAVEDLGTITLE_LABEL
},
/* Save dialog - Save button label */
{
PuiNsaveDlgSaveLabelString, PuiCSaveDlgSaveLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_saveb_label), XtRString,
(XtPointer)DEF_SAVEDLGSAVE_LABEL
},
/* Save dialog - Save for user button label */
{
PuiNsaveDlgUserLabelString, PuiCSaveDlgUserLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_userb_label), XtRString,
(XtPointer)DEF_SAVEDLGUSER_LABEL
},
/* Save dialog - Save for all users button label */
{
PuiNsaveDlgAllLabelString, PuiCSaveDlgAllLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_allb_label), XtRString,
(XtPointer)DEF_SAVEDLGALL_LABEL
},
/* Save dialog - Cancel button label */
{
PuiNsaveDlgCancelLabelString, PuiCSaveDlgCancelLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_cancelb_label), XtRString,
(XtPointer)DEF_SAVEDLGCANCEL_LABEL
},
/* Save dialog - message label */
{
PuiNsaveDlgMsgLabelString, PuiCSaveDlgMsgLabelString, XmRXmString,
sizeof(XmString), offset(printBox.res_savedlg_msg_label), XtRString,
(XtPointer)DEF_SAVEDLGMSG_LABEL
},
/* OPTIONS -------------------------------------------------------- */
/* Number of copies */
{
PuiNnumCopies, PuiCNumCopies, XtRInt, sizeof(int),
offset(printBox.res_numcopies), XtRImmediate, (XtPointer)DEF_NUM_COPIES
},
/* Copy files */
{
PuiNcopy, PuiCCopy, XtRBoolean, sizeof(Boolean),
offset(printBox.res_copy), XtRImmediate, (XtPointer)DEF_COPY
},
/* Mail on completion */
{
PuiNmail, PuiCMail, XtRBoolean, sizeof(Boolean),
offset(printBox.res_mail), XtRImmediate, (XtPointer)DEF_MAIL
},
/* Console message on completion */
{
PuiNmessage, PuiCMessage, XtRBoolean, sizeof(Boolean),
offset(printBox.res_message), XtRImmediate, (XtPointer)DEF_MESSAGE
},
/* Job title */
{
PuiNjobTitle, PuiCJobTitle, XtRString, sizeof(String),
offset(printBox.res_job_title), XtRImmediate, (XtPointer)DEF_JOB_TITLE
},
/* Printer specific options */
{
PuiNprinterOptions, PuiCPrinterOptions, XtRString, sizeof(String),
offset(printBox.res_spec_opts), XtRImmediate, (XtPointer)DEF_SPEC_OPTS
},
};
/* Core record initialization */
PuiPrintBoxClassRec puiPrintBoxClassRec = {
{ /* Core class fields */
/* superclass */ (WidgetClass) &xmBulletinBoardClassRec,
/* class_name */ "PuiPrintBox",
/* widget_size */ sizeof(PuiPrintBoxRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize */ NULL,
/* class_inited */ False,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ True,
/* compress_exposure */ True,
/* compress_enterleave */ True,
/* visible_interest */ False,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ XtInheritExpose,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ XtInheritTranslations,
/* query_geometry */ QueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL,
},
{ /* Composite class fields */
/* geometry_manager */ GeometryManager,
/* change_managed */ ChangeManaged,
/* insert_child */ InsertChild,
/* delete_child */ DeleteChild,
/* extension */ NULL,
},
{ /* Constraint class fields */
/* no additional resources */ NULL,
/* num additional resources */ 0,
/* size of constraint rec */ 0,
/* constraint_initialize */ NULL,
/* constraint_destroy */ NULL,
/* constraint_setvalue */ NULL,
/* extension */ NULL,
},
{ /* XmManager class fields */
/* default translations */ XmInheritTranslations,
/* syn_resources */ syn_resources,
/* num_syn_resources */ XtNumber(syn_resources),
/* syn_cont_resources */ NULL,
/* num_syn_cont_resources */ 0,
/* parent_process */ XmInheritParentProcess,
/* extension */ NULL,
},
{ /* XmBulletinBoard class fields */
/* always_install_accelerators */ TRUE,
/* geo_matrix_create */ XmInheritGeoMatrixCreate,
/* focus_moved_proc */ XmInheritFocusMovedProc,
/* extension */ NULL,
},
{ /* PuiPrintBox class fields */
/* dummy */ NULL,
}
};
WidgetClass puiPrintBoxWidgetClass = (WidgetClass) &puiPrintBoxClassRec;
/*
==========================================================================
STANDARD WIDGET METHODS
==========================================================================
*/
/**************************************************************************
*
* Function: ClassInitialize
*
* Description: Initialize method for the class.
*
* Parameters: none
*
* Return: none
*
**************************************************************************/
static void ClassInitialize(void)
{
/*
* Register the printing policy resource converter
*/
XtSetTypeConverter(XtRString, PuiRPrintingPolicy,
PuiCvtStringToPrintingPolicy,
(XtConvertArgList)NULL, 0,
XtCacheNone, NULL);
/*
* Register the button placement resource converter
*/
XtSetTypeConverter(XtRString, PuiRButtonPlacement,
PuiCvtStringToButtonPlacement,
(XtConvertArgList)NULL, 0,
XtCacheNone, NULL);
}
/**************************************************************************
*
* Function: Initialize
*
* Description: Widget initialization method
*
* Parameters:
* treq (I) - widget as set by arg list, resource database and defaults
* tnew (I) - new widget
* args (I) - argument list in Va creation
* num_args (I) - number of arguments
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void Initialize(Widget treq, Widget tnew,
ArgList args, Cardinal *num_args)
{
PuiPrintBoxWidget new = (PuiPrintBoxWidget)tnew;
PuiPrintBoxWidget req = (PuiPrintBoxWidget)treq;
PuiPrintBoxPart *pbp = &new->printBox;
register int i;
struct passwd *user_pw;
/*
* Set some arbitrary intial size the actual initial size
* will be determined in the ChangeManaged routine.
*/
if (WIDTH(req) <= 0)
WIDTH(new) = 5;
if (HEIGHT(req) <= 0)
HEIGHT(new) = 5;
/*
* Determine who the user is
*/
if ((user_pw = getpwuid(getuid())) == NULL) {
char buf[30];
sprintf(buf, "uid%u", getuid());
pbp->user_name = strdup(buf);
} else
pbp->user_name = strdup(user_pw->pw_name);
/*
* Initialize printer selection instance variables and
* printer specific options variables.
*/
pbp->res_num_printers = 0;
pbp->res_printer_list = NULL;
pbp->res_default_printer = NULL;
pbp->selected_printer_index = -1;
pbp->printer_options = NULL;
/*
* Initialize job submittal option variables
*/
pbp->num_copies = 1;
pbp->copy_file = 0;
pbp->mail = 0;
pbp->options = NULL;
pbp->job_title = NULL;
/*
* Initialize instance widget variables
*/
pbp->printb_widget = NULL;
pbp->user1b_widget = NULL;
pbp->user2b_widget = NULL;
pbp->user3b_widget = NULL;
pbp->user4b_widget = NULL;
pbp->optionsb_widget = NULL;
pbp->saveb_widget = NULL;
pbp->cancelb_widget = NULL;
pbp->helpb_widget = NULL;
pbp->files_label_widget = NULL;
pbp->plist_label_widget = NULL;
pbp->opts_label_widget = NULL;
pbp->files_widget = NULL;
pbp->plist_widget = NULL;
pbp->pf_form = NULL;
pbp->option_form = NULL;
pbp->action_form = NULL;
pbp->action_rc = NULL;
pbp->opts_rc_widget = NULL;
pbp->opts_sw_widget = NULL;
pbp->work_area = NULL;
pbp->separator = NULL;
pbp->numcopies_label_widget = NULL;
pbp->title_label_widget = NULL;
pbp->complete_label_widget = NULL;
pbp->handling_label_widget = NULL;
pbp->spec_options_label_widget = NULL;
pbp->save_dialog_widget = NULL;
pbp->save_list_widget = NULL;
pbp->save_msg_widget = NULL;
/*
* For my resources that are strings I need to make copies
* so that the user can free storage for any string he passes
* in
*/
if (pbp->res_printer)
pbp->res_printer = XtNewString(pbp->res_printer);
if (pbp->res_filename)
pbp->res_filename = XtNewString(pbp->res_filename);
if (pbp->res_job_title)
pbp->res_job_title = XtNewString(pbp->res_job_title);
if (pbp->res_spec_opts)
pbp->res_spec_opts = XtNewString(pbp->res_spec_opts);
/*
* Indicate that we are adding our own child widgets
*/
pbp->adding_pb_widgets = True;
/*
* Create the major dialog UI areas
*/
CreateControlArea(new);
CreateActionArea(new);
/*
* Create the save options dialog. Note that we cannot lazy
* evaluate the dialog creation since we need to have the
* dialog around for label resource queries.
*/
pbp->save_dialog_widget = CreateSaveDialog(new);
/*
* Indicate that we are no longer adding widgets
*/
pbp->adding_pb_widgets = False;
/*
* Initialize text field foreground, background and shadow color instance
* entries for use in making the text fields insensitive. Then
* make sure everything starts off with the desired sensitivity.
*/
InitTextFieldColors(new);
SetTextFieldSensitivity(pbp, pbp->files_widget,
pbp->res_filename_sensitive);
SetTextFieldSensitivity(pbp, pbp->numcopies_text_widget,
pbp->res_numcopies_sensitive);
SetTextFieldSensitivity(pbp, pbp->spec_options_widget,
pbp->res_poptions_sensitive);
/*
* Initialize the option objects
*/
for (i = 0; i < num_options; i++)
option_list[i].set_func(pbp);
/*
* Read the spooling system options and set the UI accordingly.
* Note that we do this after setting the UI from the resources
* so that the glprc file settings take precedence over the
* resources set when the widget is created. Any subsequent set
* values on the resource will then override the glprc setting.
*/
ReadSpoolerOptionsFile(pbp);
/*
* Set the spooler to System V and set the list of printers.
*/
pbp->init_error_code = 0;
if (SLSetSpooler(SL_SPOOLER_SYSV) < 0)
pbp->init_error_code = SLerrno;
else
pbp->init_error_code = SetPrinterList(new);
/*
* Initialize the option panel array
*/
pbp->option_panels = NULL;
if (pbp->res_show_optionsbutton && pbp->res_num_printers > 0) {
pbp->option_panels = (PuiOptionPanel**)XtCalloc(pbp->res_num_printers,
sizeof(PuiOptionPanel*));
}
/*
* Select the appropriate printer
*/
SetPrinter(pbp);
/*
* Initialize the filename
*/
SetFilenames(pbp);
/*
* A number of the string resources we support are actually fronts
* for our children widgets. We will let the children maintain the
* state of these resources and we will query the children when we
* get a GetValues for these resources. Normally we will keep these
* resources set to NULL on our side.
*/
pbp->res_printb_label = NULL;
pbp->res_user1b_label = NULL;
pbp->res_user2b_label = NULL;
pbp->res_user3b_label = NULL;
pbp->res_user4b_label = NULL;
pbp->res_optionsb_label = NULL;
pbp->res_saveb_label = NULL;
pbp->res_cancelb_label = NULL;
pbp->res_helpb_label = NULL;
pbp->res_files_label = NULL;
pbp->res_plist_label = NULL;
pbp->res_opts_label = NULL;
pbp->res_numcopies_label = NULL;
pbp->res_title_label = NULL;
pbp->res_deftitle_label = NULL;
pbp->res_spectitle_label = NULL;
pbp->res_complete_label = NULL;
pbp->res_complete_mail_label = NULL;
pbp->res_complete_mess_label = NULL;
pbp->res_handling_label = NULL;
pbp->res_handling_copy_label = NULL;
pbp->res_handling_link_label = NULL;
pbp->res_spec_options_label = NULL;
pbp->res_savedlg_title_label = NULL;
pbp->res_savedlg_saveb_label = NULL;
pbp->res_savedlg_userb_label = NULL;
pbp->res_savedlg_allb_label = NULL;
pbp->res_savedlg_cancelb_label = NULL;
pbp->res_savedlg_msg_label = NULL;
}
/**************************************************************************
*
* Function: Destroy
*
* Description: Cleans up local allocations
*
* Parameters:
* w (I) - this widget
*
* Return: none
*
**************************************************************************/
static void Destroy(Widget w)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)w;
PuiPrintBoxPart *pbp = &pb->printBox;
register int i;
/*
* Destroy all option panel instances and free the lsit
*/
if (pbp->option_panels) {
for (i = 0; i < pbp->res_num_printers; i++)
if (pbp->option_panels[i])
_PuiOptionPanelDestroy(pbp->option_panels[i]);
XtFree((char*)pbp->option_panels);
}
/*
* Free the printer list
*/
FreePrinterList(pbp->res_printer_list, pbp->res_num_printers);
/*
* Deallocate string storage
*/
if (pbp->res_printer)
XtFree(pbp->res_printer);
if (pbp->res_filename)
XtFree(pbp->res_filename);
if (pbp->res_job_title)
XtFree(pbp->res_job_title);
if (pbp->res_spec_opts)
XtFree(pbp->res_spec_opts);
/*
* Remove all callbacks
*/
XtRemoveAllCallbacks(w, PuiNprintCallback);
XtRemoveAllCallbacks(w, PuiNuser1Callback);
XtRemoveAllCallbacks(w, PuiNuser2Callback);
XtRemoveAllCallbacks(w, PuiNuser3Callback);
XtRemoveAllCallbacks(w, PuiNuser4Callback);
XtRemoveAllCallbacks(w, PuiNsaveCallback);
XtRemoveAllCallbacks(w, PuiNcancelCallback);
XtRemoveAllCallbacks(w, PuiNhelpCallback);
XtRemoveAllCallbacks(w, PuiNjobInfoCallback);
XtRemoveAllCallbacks(w, PuiNprinterSelectCallback);
XtRemoveAllCallbacks(w, PuiNerrorCallback);
XtRemoveAllCallbacks(w, PuiNoptionErrorCallback);
}
/**************************************************************************
*
* Function: ChangeManaged
*
* Description: Handles the initial geometry determination, dispatches
* error callbacks for initialization errors and selects the initial
* printer.
*
* Parameters:
* w (I) - this widget
*
* Return: none
*
**************************************************************************/
static void ChangeManaged(Widget w)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)w;
PuiPrintBoxPart *pbp = &pb->printBox;
int total_width, total_height;
DEFARGS(5);
/*
* Properly center the action area buttons if they have
* center placement
*/
if (pbp->res_button_placement == PuiBUTTONS_CENTER) {
STARTARGS;
SETARG(XmNleftOffset, -WIDTH(pbp->action_rc)/2);
XtSetValues(pbp->action_rc, ARGLIST);
}
/*
* Handle calculations and actions that must be done only on widget
* realization
*/
if (!XtIsRealized(w)) {
/*
* If we had an error occurr during initialization we want
* to handle it on realization.
*/
if (pbp->init_error_code != 0)
HandleError(pb, pbp->init_error_code);
/*
* Set the width and height of the printer list to encompass
* the width of the list items
*/
SetPrinterListSize(pbp);
/*
* Set the width and height of the option scrolled window to encompass
* all options and not show any scrollbars
*/
SetOptionsSize(pbp);
/*
* Set the width of the action area form
*/
SetActionAreaSize(pbp);
}
/*
* Calculate the required overall widget dimensions based
* on the size of the children
*/
CalculateMySize(pb, &total_width, &total_height);
/*
* Set a size for the overall widget
*/
XtMakeResizeRequest(w, total_width, total_height, NULL, NULL);
/*
* Position and size all children
*/
DoLayout(pb);
}
/**************************************************************************
*
* Function: GeometryManager
*
* Description: A yes man for geometry management in our widget.
*
* Parameters:
* w (I) - this widget
* request (I) - requested geometry
* reply (O) - allowable geometry
*
* Return: In our case, always XtGeometryYes.
*
**************************************************************************/
/* ARGSUSED */
static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
int new_width, new_height;
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)XtParent(w);
/*
* If the request concerns size or positioning then do some
* processing. For all other requests simply accept the
* request
*/
if (REQUEST_MODE(request, CWX|CWY|CWWidth|CWHeight|CWBorderWidth)) {
/*
* If query only return yes since we allow any configuration
*/
if (REQUEST_MODE(request, XtCWQueryOnly))
return XtGeometryYes;
/*
* Set the new values
*/
if (REQUEST_MODE(request, CWX))
XPOS(w) = request->x;
if (REQUEST_MODE(request, CWY))
YPOS(w) = request->y;
if (REQUEST_MODE(request, CWWidth))
WIDTH(w) = request->width;
if (REQUEST_MODE(request, CWHeight))
HEIGHT(w) = request->height;
if (REQUEST_MODE(request, CWBorderWidth))
BWIDTH(w) = request->border_width;
/*
* Calculate a new overall size and attempt to set this size
* then relayout the children
*/
CalculateMySize(pb, &new_width, &new_height);
if (new_width != WIDTH(pb) || new_height != HEIGHT(pb))
XtMakeResizeRequest((Widget)pb, new_width, new_height, NULL, NULL);
DoLayout(pb);
return XtGeometryYes;
}
return XtGeometryYes;
}
/**************************************************************************
*
* Function: QueryGeometry
*
* Description: Responds to a query for widget size changes
*
* Parameters:
* w (I) - this widget
* request (I) - proposed new geometry
* reply (O) - our response
*
* Return: Response to change request
*
**************************************************************************/
/* ARGSUSED */
static XtGeometryResult QueryGeometry(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
XtGeometryResult result;
request->request_mode &= CWWidth | CWHeight;
/*
* Parent isn't going to change width or height so agree
*/
if (request->request_mode == 0)
return XtGeometryYes;
/*
* Clear reply request mode
*/
reply->request_mode = 0;
/*
* If proposed size is large enough, accept it. Otherwise,
* suggest an arbitrary minimum size
*/
if (request->request_mode & CWHeight) {
if (request->height < 5) {
result = XtGeometryAlmost;
reply->height = 5;
reply->request_mode |= CWHeight;
} else
result = XtGeometryYes;
}
if (request->request_mode & CWWidth) {
if (request->width < 5) {
result = XtGeometryAlmost;
reply->width = 5;
reply->request_mode |= CWWidth;
} else
result = XtGeometryYes;
}
return result;
}
/**************************************************************************
*
* Function: Resize
*
* Description: Handles the resizing of the widget
*
* Parameters:
* w (I) - this widget
*
* Return: none
*
**************************************************************************/
static void Resize(Widget w)
{
/*
* Call our superclass's resize routine to do whatever it
* needs to do (e.g. handle redrawing of shadows).
*/
(*((XmBulletinBoardWidgetClass)xmBulletinBoardWidgetClass)
->core_class.resize)(w);
DoLayout((PuiPrintBoxWidget)w);
}
/**************************************************************************
*
* Function: InsertChild
*
* Description: Handles the insertion of a user defined work area. Only
* one work area child is allowed.
*
* Parameters:
* child (I) - child widget to be inserted
*
* Return: none
*
**************************************************************************/
static void InsertChild(Widget child)
{
PuiPrintBoxWidget pb;
/*
* Get a pointer to our class part. The child parent is, by definition
* our widget.
*/
pb = (PuiPrintBoxWidget)XtParent(child);
/*
* If we are adding our own internal widgets then pass thru. Otherwise
* check if we already have a work area and is so issue a warning
*/
if (!pb->printBox.adding_pb_widgets) {
if (pb->printBox.work_area)
XtError(gettxt(_SGI_LIBPRINTUI_ONE_CHILD,
"PuiPrintBox - only one work area child widget allowed"));
pb->printBox.work_area = child;
}
/*
* Call our superclass's insert_child routine to do the
* dirty work of inserting the child in the proper data
* structures
*/
(*((XmBulletinBoardWidgetClass)xmBulletinBoardWidgetClass)
->composite_class.insert_child)(child);
}
/**************************************************************************
*
* Function: DeleteChild
*
* Description: Handles the deletion of a user defined work area.
*
* Parameters:
* child (I) - child widget to be deleted
*
* Return: none
*
**************************************************************************/
static void DeleteChild(Widget child)
{
PuiPrintBoxWidget pb;
PuiPrintBoxPart *pbp;
/*
* Get a pointer to our class part. The child parent is, by definition
* our widget.
*/
pb = (PuiPrintBoxWidget)XtParent(child);
pbp = &pb->printBox;
/*
* NULL out the proper widget variable
*/
if (child == pbp->work_area)
pbp->work_area = NULL;
else if (child == pbp->separator)
pbp->separator = NULL;
/*
* Call our superclass's delete_child routine to do the
* dirty work of deleting the child in the proper data
* structures
*/
(*((XmBulletinBoardWidgetClass)xmBulletinBoardWidgetClass)
->composite_class.delete_child)(child);
}
/**************************************************************************
*
* Function: SetValues
*
* Description: Handles the setting of resource values by the XtSetValues
* Xt function.
*
* Parameters:
* cur (I) - current settings of widget variables
* req (I) - requested values of widget variables not processed
* by superclass.
* new (I) - new widget values already processed by superclass
* args (I) - arguments to SetValues function
* num_args (I) - number of arguments in args
*
* Return: True if XClearArea is to be called and expose event generated,
* Flase if no redisplay required.
*
**************************************************************************/
/* ARGSUSED */
static Boolean SetValues(Widget cur, Widget req, Widget new,
ArgList args, Cardinal *num_args)
{
PuiPrintBoxWidget cpb = (PuiPrintBoxWidget) cur;
PuiPrintBoxPart *cpbp = &cpb->printBox;
PuiPrintBoxWidget npb = (PuiPrintBoxWidget) new;
PuiPrintBoxPart *npbp = &npb->printBox;
PuiPrintBoxWidget rpb = (PuiPrintBoxWidget) req;
PuiPrintBoxPart *rpbp = &rpb->printBox;
/*
* PRINTER LIST INFO
*/
/* List of printers available */
if (cpbp->res_printer_list != npbp->res_printer_list) {
npbp->res_printer_list = cpbp->res_printer_list;
XtWarning(gettxt(_SGI_LIBPRINTUI_PLIST_RO,
"PuiPrintBox - cannot change printerList (read-only)"));
}
/* Number of printers available */
if (cpbp->res_num_printers != npbp->res_num_printers) {
npbp->res_num_printers = cpbp->res_num_printers;
XtWarning(gettxt(_SGI_LIBPRINTUI_NUMP_RO,
"PuiPrintBox - cannot change numPrinters (read-only)"));
}
/* Default printer */
if (cpbp->res_default_printer != npbp->res_default_printer) {
npbp->res_default_printer = cpbp->res_default_printer;
XtWarning(gettxt(_SGI_LIBPRINTUI_DEFP_RO,
"PuiPrintBox - cannot change defPrinter (read-only)"));
}
/*
* BASIC INFO
*/
/* Job Type */
if (cpbp->res_job_type != npbp->res_job_type) {
npbp->res_job_type = cpbp->res_job_type;
XtWarning(gettxt(_SGI_LIBPRINTUI_JOBTYPE,
"PuiPrintBox - cannot change jobType after creation"));
}
/* Filename */
if (cpbp->res_filename != npbp->res_filename) {
SetFilenames(npbp);
SetStringValue(&cpbp->res_filename, &rpbp->res_filename,
&npbp->res_filename);
}
/* Filename field display */
if (cpbp->res_show_fname != npbp->res_show_fname) {
npbp->res_show_fname = cpbp->res_show_fname;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWFNAME,
"PuiPrintBox - cannot change showFilename after creation"));
}
/* Options display */
if (cpbp->res_show_opts != npbp->res_show_opts) {
npbp->res_show_opts = cpbp->res_show_opts;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWOPT,
"PuiPrintBox - cannot change showOptions after creation"));
}
/* Number of copies option display */
if (cpbp->res_show_numcopies != npbp->res_show_numcopies) {
npbp->res_show_numcopies = cpbp->res_show_numcopies;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWNUMCOPIES,
"PuiPrintBox - cannot change showNumCopies after creation"));
}
/* Banner page title option display */
if (cpbp->res_show_bannertitle != npbp->res_show_bannertitle) {
npbp->res_show_bannertitle = cpbp->res_show_bannertitle;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWBANNERTITLE,
"PuiPrintBox - cannot change showBannerTitle after creation"));
}
/* Job completion notification option display */
if (cpbp->res_show_completion != npbp->res_show_completion) {
npbp->res_show_completion = cpbp->res_show_completion;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWCOMPLETION,
"PuiPrintBox - cannot change showCompletion after creation"));
}
/* Print job handling option display */
if (cpbp->res_show_handling != npbp->res_show_handling) {
npbp->res_show_handling = cpbp->res_show_handling;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWHANDLING,
"PuiPrintBox - cannot change showHandling after creation"));
}
/* Printer specific options display */
if (cpbp->res_show_printeroptions != npbp->res_show_printeroptions) {
npbp->res_show_printeroptions = cpbp->res_show_printeroptions;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWPRINTEROPTIONS,
"PuiPrintBox - cannot change showPrinterOptions after creation"));
}
/* Options button display */
if (cpbp->res_show_optionsbutton != npbp->res_show_optionsbutton) {
npbp->res_show_optionsbutton = cpbp->res_show_optionsbutton;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWOPTIONSBUTTON,
"PuiPrintBox - cannot change showOptionsButton after creation"));
}
/* Save button display */
if (cpbp->res_show_savebutton != npbp->res_show_savebutton) {
npbp->res_show_savebutton = cpbp->res_show_savebutton;
XtWarning(gettxt(_SGI_LIBPRINTUI_SHOWSAVEBUTTON,
"PuiPrintBox - cannot change showSaveButton after creation"));
}
/* Action area button placement */
if (cpbp->res_button_placement != npbp->res_button_placement) {
npbp->res_button_placement = cpbp->res_button_placement;
XtWarning(gettxt(_SGI_LIBPRINTUI_BPLACE,
"PuiPrintBox - cannot change buttonPlacement after creation"));
}
/* Action area button spacing */
if (cpbp->res_button_spacing != npbp->res_button_spacing) {
npbp->res_button_spacing = cpbp->res_button_spacing;
XtWarning(gettxt(_SGI_LIBPRINTUI_BSPACE,
"PuiPrintBox - cannot change buttonSpacing after creation"));
}
/* Printer list visible item count */
if (cpbp->res_vis_count != npbp->res_vis_count) {
npbp->res_vis_count = cpbp->res_vis_count;
XtWarning(gettxt(_SGI_LIBPRINTUI_VISCOUNT,
"PuiPrintBox - cannot change listVisibleItemCount after creation"));
}
/* Printer */
if (cpbp->res_printer != npbp->res_printer) {
if (!npbp->res_printer) {
npbp->res_printer = cpbp->res_printer;
XtWarning(gettxt(_SGI_LIBPRINTUI_PNAME,
"PuiPrintBox - printer name cannot be NULL"));
} else {
npbp->selected_printer_index = FindPrinter(npbp, npbp->res_printer);
if (XtIsManaged(new))
SetPrinter(npbp);
SetStringValue(&cpbp->res_printer, &rpbp->res_printer,
&npbp->res_printer);
}
}
/*
* TEXT FIELD SENSITIVITY
*/
/* Insensitive foreground color */
if (cpbp->tfield_insensitive.foreground !=
npbp->tfield_insensitive.foreground) {
SetTextFieldSensitivity(npbp, npbp->files_widget,
npbp->res_filename_sensitive);
SetTextFieldSensitivity(npbp, npbp->numcopies_text_widget,
npbp->res_numcopies_sensitive);
SetTextFieldSensitivity(npbp, npbp->spec_options_widget,
npbp->res_poptions_sensitive);
}
/* Insensitive background color */
if (cpbp->tfield_insensitive.background !=
npbp->tfield_insensitive.background) {
SetTextFieldSensitivity(npbp, npbp->files_widget,
npbp->res_filename_sensitive);
SetTextFieldSensitivity(npbp, npbp->numcopies_text_widget,
npbp->res_numcopies_sensitive);
SetTextFieldSensitivity(npbp, npbp->spec_options_widget,
npbp->res_poptions_sensitive);
}
/* Filename field sensitivity */
if (cpbp->res_filename_sensitive != npbp->res_filename_sensitive)
SetTextFieldSensitivity(npbp, npbp->files_widget,
npbp->res_filename_sensitive);
/* Number of copies field sensitivity */
if (cpbp->res_numcopies_sensitive != npbp->res_numcopies_sensitive)
SetTextFieldSensitivity(npbp, npbp->numcopies_text_widget,
npbp->res_numcopies_sensitive);
/* Print options field sensitivity */
if (cpbp->res_poptions_sensitive != npbp->res_poptions_sensitive)
SetTextFieldSensitivity(npbp, npbp->spec_options_widget,
npbp->res_poptions_sensitive);
/*
* FONTS
*/
if (cpbp->res_printer_font != npbp->res_printer_font) {
npbp->res_printer_font = cpbp->res_printer_font;
XtWarning(gettxt(_SGI_LIBPRINTUI_PFONT,
"PuiPrintBox - cannot change printerFont after creation"));
}
if (cpbp->res_def_printer_font != npbp->res_def_printer_font) {
npbp->res_def_printer_font = cpbp->res_def_printer_font;
XtWarning(gettxt(_SGI_LIBPRINTUI_DEFPFONT,
"PuiPrintBox - cannot change defaultPrinterFont after creation"));
}
/*
* LABELS
*/
if (cpbp->res_printb_label != npbp->res_printb_label)
UpdateLabel(npbp->printb_widget, XmNlabelString,
&npbp->res_printb_label);
if (cpbp->res_user1b_label != npbp->res_user1b_label)
UpdateLabel(npbp->user1b_widget, XmNlabelString,
&npbp->res_user1b_label);
if (cpbp->res_user2b_label != npbp->res_user2b_label)
UpdateLabel(npbp->user2b_widget, XmNlabelString,
&npbp->res_user2b_label);
if (cpbp->res_user3b_label != npbp->res_user3b_label)
UpdateLabel(npbp->user3b_widget, XmNlabelString,
&npbp->res_user3b_label);
if (cpbp->res_user4b_label != npbp->res_user4b_label)
UpdateLabel(npbp->user4b_widget, XmNlabelString,
&npbp->res_user4b_label);
if (cpbp->res_optionsb_label != npbp->res_optionsb_label)
UpdateLabel(npbp->optionsb_widget, XmNlabelString,
&npbp->res_optionsb_label);
if (cpbp->res_saveb_label != npbp->res_saveb_label)
UpdateLabel(npbp->saveb_widget, XmNlabelString,
&npbp->res_saveb_label);
if (cpbp->res_cancelb_label != npbp->res_cancelb_label)
UpdateLabel(npbp->cancelb_widget, XmNlabelString,
&npbp->res_cancelb_label);
if (cpbp->res_helpb_label != npbp->res_helpb_label)
UpdateLabel(npbp->helpb_widget, XmNlabelString,
&npbp->res_helpb_label);
if (cpbp->res_files_label != npbp->res_files_label)
UpdateLabel(npbp->files_label_widget, XmNlabelString,
&npbp->res_files_label);
if (cpbp->res_plist_label != npbp->res_plist_label)
UpdateLabel(npbp->plist_label_widget, XmNlabelString,
&npbp->res_plist_label);
if (cpbp->res_opts_label != npbp->res_opts_label)
UpdateLabel(npbp->opts_label_widget, XmNlabelString,
&npbp->res_opts_label);
if (cpbp->res_numcopies_label != npbp->res_numcopies_label)
UpdateLabel(npbp->numcopies_label_widget, XmNlabelString,
&npbp->res_numcopies_label);
if (cpbp->res_title_label != npbp->res_title_label)
UpdateLabel(npbp->title_label_widget, XmNlabelString,
&npbp->res_title_label);
if (cpbp->res_deftitle_label != npbp->res_deftitle_label)
UpdateLabel(npbp->banner_deftitle_widget, XmNlabelString,
&npbp->res_deftitle_label);
if (cpbp->res_spectitle_label != npbp->res_spectitle_label)
UpdateLabel(npbp->banner_spectitle_widget, XmNlabelString,
&npbp->res_spectitle_label);
if (cpbp->res_complete_label != npbp->res_complete_label)
UpdateLabel(npbp->complete_label_widget, XmNlabelString,
&npbp->res_complete_label);
if (cpbp->res_complete_mail_label != npbp->res_complete_mail_label)
UpdateLabel(npbp->complete_mail_widget, XmNlabelString,
&npbp->res_complete_mail_label);
if (cpbp->res_complete_mess_label != npbp->res_complete_mess_label)
UpdateLabel(npbp->complete_mess_widget, XmNlabelString,
&npbp->res_complete_mess_label);
if (cpbp->res_handling_label != npbp->res_handling_label)
UpdateLabel(npbp->handling_label_widget, XmNlabelString,
&npbp->res_handling_label);
if (cpbp->res_handling_copy_label != npbp->res_handling_copy_label)
UpdateLabel(npbp->handling_copy_widget, XmNlabelString,
&npbp->res_handling_copy_label);
if (cpbp->res_handling_link_label != npbp->res_handling_link_label)
UpdateLabel(npbp->handling_link_widget, XmNlabelString,
&npbp->res_handling_link_label);
if (cpbp->res_spec_options_label != npbp->res_spec_options_label)
UpdateLabel(npbp->spec_options_label_widget, XmNlabelString,
&npbp->res_spec_options_label);
if (cpbp->res_savedlg_title_label != npbp->res_savedlg_title_label)
UpdateLabel(npbp->save_dialog_widget, XmNdialogTitle,
&npbp->res_savedlg_title_label);
if (strcmp(npbp->user_name, "root") && strcmp(npbp->user_name, "lp")) {
if (cpbp->res_savedlg_saveb_label != npbp->res_savedlg_saveb_label)
UpdateLabel(npbp->save_dialog_widget, XmNokLabelString,
&npbp->res_savedlg_saveb_label);
} else {
if (cpbp->res_savedlg_userb_label != npbp->res_savedlg_userb_label)
UpdateLabel(npbp->save_dialog_widget, XmNokLabelString,
&npbp->res_savedlg_userb_label);
}
if (cpbp->res_savedlg_allb_label != npbp->res_savedlg_allb_label)
UpdateLabel(npbp->save_dialog_widget, XmNcancelLabelString,
&npbp->res_savedlg_allb_label);
if (cpbp->res_savedlg_cancelb_label != npbp->res_savedlg_cancelb_label)
UpdateLabel(npbp->save_dialog_widget, XmNhelpLabelString,
&npbp->res_savedlg_cancelb_label);
if (cpbp->res_savedlg_msg_label != npbp->res_savedlg_msg_label)
UpdateLabel(npbp->save_msg_widget, XmNlabelString,
&npbp->res_savedlg_msg_label);
/*
* OPTIONS
*/
/* Number of copies */
if (cpbp->res_numcopies != npbp->res_numcopies)
SetOptionNumCopies(npbp);
/* Banner page */
if (cpbp->res_job_title != npbp->res_job_title) {
SetOptionBanner(npbp);
SetStringValue(&cpbp->res_job_title, &rpbp->res_job_title,
&npbp->res_job_title);
}
/* Copy file */
if (cpbp->res_copy != npbp->res_copy)
SetOptionJobHandling(npbp);
/* Mail and Message */
if (cpbp->res_mail != npbp->res_mail ||
cpbp->res_message != npbp->res_message)
SetOptionCompletion(npbp);
/* Printer specific options */
if (cpbp->res_spec_opts != npbp->res_spec_opts) {
SetOptionPrinterSpecific(npbp);
SetStringValue(&cpbp->res_spec_opts, &rpbp->res_spec_opts,
&npbp->res_spec_opts);
if (npbp->selected_printer_index >= 0)
UpdatePrinterOption(npb,
&npbp->printer_options[npbp->selected_printer_index]);
}
return False;
}
/*
==========================================================================
PRIVATE WIDGET METHODS
==========================================================================
*/
/**************************************************************************
*
* Function: CreateActionArea
*
* Description: Creates the action area widgets. The action area is the
* area at the bottom of the box that contains the 'Print', 'Help',
* etc. buttons.
*
* Parameters:
* pb (I) - this widget
*
* Return: none
*
**************************************************************************/
static void CreateActionArea(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
DEFARGS(15);
/*
* Create the separator
*/
pbp->separator = XtCreateManagedWidget("actionSeparator",
xmSeparatorWidgetClass,
(Widget)pb, NULL, 0);
/*
* Create a form so that we can adhere the buttons to the right
* end of it
*/
STARTARGS;
SETARG(XmNskipAdjust, True);
pbp->action_form = XtCreateManagedWidget("actionForm", xmFormWidgetClass,
(Widget)pb, ARGLIST);
/*
* Create a RowColumn to actually hold the buttons
*/
STARTARGS;
SETARG(XmNorientation, XmHORIZONTAL);
SETARG(XmNpacking, XmPACK_COLUMN);
SETARG(XmNentryAlignment, XmALIGNMENT_CENTER);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
SETARG(XmNspacing, pbp->res_button_spacing);
SETARG(XmNtopAttachment, XmATTACH_FORM);
SETARG(XmNbottomAttachment, XmATTACH_FORM);
if (pbp->res_button_placement == PuiBUTTONS_LEFT) {
SETARG(XmNleftAttachment, XmATTACH_FORM);
} else if (pbp->res_button_placement == PuiBUTTONS_RIGHT) {
SETARG(XmNrightAttachment, XmATTACH_FORM);
} else {
SETARG(XmNleftAttachment, XmATTACH_POSITION);
SETARG(XmNleftPosition, 50);
}
pbp->action_rc = XtCreateManagedWidget("actionRowC",
xmRowColumnWidgetClass,
pbp->action_form, ARGLIST);
/*
* Create the action area buttons
*/
/* Print button */
STARTARGS;
SETARG(XmNlabelString, pbp->res_printb_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_PRINT_BUTTON);
pbp->printb_widget = XtCreateManagedWidget(DEF_PRINTB_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
/* User buttons 1-4. Must be explicitly managed by app. */
STARTARGS;
SETARG(XmNlabelString, pbp->res_user1b_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_USER1_BUTTON);
pbp->user1b_widget = XtCreateWidget(DEF_USER1B_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_user2b_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_USER2_BUTTON);
pbp->user2b_widget = XtCreateWidget(DEF_USER2B_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_user3b_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_USER3_BUTTON);
pbp->user3b_widget = XtCreateWidget(DEF_USER3B_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_user4b_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_USER4_BUTTON);
pbp->user4b_widget = XtCreateWidget(DEF_USER4B_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
/* Options button */
STARTARGS;
SETARG(XmNlabelString, pbp->res_optionsb_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_OPTIONS_BUTTON);
pbp->optionsb_widget = XtCreateWidget(DEF_OPTIONSB_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
if (pbp->res_show_optionsbutton) {
XtManageChild(pbp->optionsb_widget);
XtSetSensitive(pbp->optionsb_widget, False);
}
/* Save button */
STARTARGS;
SETARG(XmNlabelString, pbp->res_saveb_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_SAVE_BUTTON);
pbp->saveb_widget = XtCreateWidget(DEF_SAVEB_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
if (pbp->res_show_savebutton)
XtManageChild(pbp->saveb_widget);
/* Cancel button. Set as BB's cancel button */
STARTARGS;
SETARG(XmNlabelString, pbp->res_cancelb_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_CANCEL_BUTTON);
pb->bulletin_board.cancel_button = pbp->cancelb_widget =
XtCreateManagedWidget(DEF_CANCELB_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
/* Help button */
STARTARGS;
SETARG(XmNlabelString, pbp->res_helpb_label);
SETARG(XmNuserData, (XtPointer)PuiPRINTBOX_HELP_BUTTON);
pbp->helpb_widget = XtCreateManagedWidget(DEF_HELPB_LABEL,
xmPushButtonWidgetClass,
pbp->action_rc, ARGLIST);
/*
* Register the action area button callbacks
*/
XtAddCallback(pbp->printb_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->user1b_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->user2b_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->user3b_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->user4b_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->saveb_widget, XmNactivateCallback, QueryForSaveCB,
(XtPointer)pb);
XtAddCallback(pbp->cancelb_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
XtAddCallback(pbp->helpb_widget, XmNactivateCallback, ActionAreaCB,
(XtPointer)pb);
/*
* Register the option button callback
*/
XtAddCallback(pbp->optionsb_widget, XmNactivateCallback, OptionButtonCB,
(XtPointer)pb);
/*
* Register the default print callback
*/
XtAddCallback(pbp->printb_widget, XmNactivateCallback,
SubmitPrintJobCB, (XtPointer)pb);
/*
* If parent is a dialog shell and BB's autoUnmanage resource it true
* register the unamange callback
*/
if (XmIsDialogShell(XtParent(pb)) && pb->bulletin_board.auto_unmanage) {
XtAddCallback(pbp->printb_widget, XmNactivateCallback,
UnmanageCB, (XtPointer)pb);
XtAddCallback(pbp->cancelb_widget, XmNactivateCallback,
UnmanageCB, (XtPointer)pb);
}
}
/**************************************************************************
*
* Function: CreateControlArea
*
* Description: Creates the control area widgets. The control area is the
* area where printers are selected and job printing options are set.
*
* Parameters:
* pb (I) - this widget
*
* Return: none
*
**************************************************************************/
static void CreateControlArea(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
XmFontList flist, nlist;
XmFontListEntry printer_entry, defprinter_entry;
DEFARGS(15);
Widget wlist[2], clip;
Pixel bg;
/*
* Create the file and printer selection section
*/
pbp->pf_form = XtCreateManagedWidget("printerFileForm",
xmFormWidgetClass,
(Widget)pb, NULL, 0);
/*
* Filename selection section
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_files_label);
SETARG(XmNtopAttachment, XmATTACH_FORM);
SETARG(XmNleftAttachment, XmATTACH_FORM);
wlist[0] = pbp->files_label_widget = XtCreateWidget(DEF_FILES_LABEL,
xmLabelWidgetClass,
pbp->pf_form, ARGLIST);
STARTARGS;
SETARG(XmNtopAttachment, XmATTACH_WIDGET);
SETARG(XmNtopWidget, pbp->files_label_widget);
SETARG(XmNleftAttachment, XmATTACH_FORM);
SETARG(XmNrightAttachment, XmATTACH_FORM);
wlist[1] = pbp->files_widget = XtCreateWidget("fileText",
xmTextFieldWidgetClass,
pbp->pf_form, ARGLIST);
if (pbp->res_job_type == PuiPRINTJOB_FILENAME && pbp->res_show_fname)
XtManageChildren(wlist, 2);
/*
* Register the sensitivity check on filename entry
*/
XtAddCallback(pbp->files_widget, XmNvalueChangedCallback,
PrintSensitiveCB, (XtPointer)pbp);
/*
* Register character verify check on filename entry
*/
XtAddCallback(pbp->files_widget, XmNmodifyVerifyCallback,
_PuiCharacterVerifyCB, (XtPointer)TYPEIN_BAD_CHARS);
/*
* Printer selection section
*/
STARTARGS;
if (pbp->res_job_type == PuiPRINTJOB_FILENAME && pbp->res_show_fname) {
SETARG(XmNtopAttachment, XmATTACH_WIDGET);
SETARG(XmNtopWidget, pbp->files_widget);
SETARG(XmNtopOffset, MARGIN_HEIGHT(pb) - 4);
} else {
SETARG(XmNtopAttachment, XmATTACH_FORM);
}
SETARG(XmNleftAttachment, XmATTACH_FORM);
SETARG(XmNlabelString, pbp->res_plist_label);
SETARG(XmNalignment, XmALIGNMENT_BEGINNING);
pbp->plist_label_widget = XtCreateManagedWidget(DEF_PLIST_LABEL,
xmLabelWidgetClass,
pbp->pf_form, ARGLIST);
STARTARGS;
SETARG(XmNtopAttachment, XmATTACH_WIDGET);
SETARG(XmNtopWidget, pbp->plist_label_widget);
SETARG(XmNbottomAttachment, XmATTACH_FORM);
SETARG(XmNleftAttachment, XmATTACH_FORM);
SETARG(XmNrightAttachment, XmATTACH_FORM);
SETARG(XmNvisibleItemCount, pbp->res_vis_count);
pbp->plist_widget = XmCreateScrolledList(pbp->pf_form,
"printerSelectionList",
ARGLIST);
XtManageChild(pbp->plist_widget);
/*
* Register the printer selection and action callbacks. The
* selection callback is called when a printer is selected
* with a single click from the list. The action callback is
* invoked when a printer on the list is double-clicked.
*/
XtAddCallback(pbp->plist_widget, XmNbrowseSelectionCallback,
PrinterSelectedCB, (XtPointer)pb);
XtAddCallback(pbp->plist_widget, XmNdefaultActionCallback,
PrinterSelectedCB, (XtPointer)pb);
/*
* Add the normal and default printer fonts to the list's fontlist
*/
printer_entry = XmFontListEntryCreate(PRINTER_CHARSET,
XmFONT_IS_FONT,
pbp->res_printer_font);
defprinter_entry = XmFontListEntryCreate(DEF_PRINTER_CHARSET,
XmFONT_IS_FONT,
pbp->res_def_printer_font);
STARTARGS;
SETARG(XmNfontList, &flist);
XtGetValues(pbp->plist_widget, ARGLIST);
nlist = XmFontListCopy(flist);
nlist = XmFontListAppendEntry(nlist, printer_entry);
nlist = XmFontListAppendEntry(nlist, defprinter_entry);
STARTARGS;
SETARG(XmNfontList, nlist);
XtSetValues(pbp->plist_widget, ARGLIST);
XmFontListFree(nlist);
XmFontListEntryFree(&printer_entry);
XmFontListEntryFree(&defprinter_entry);
/*
* Create the print job option area
*/
pbp->option_form = XtCreateWidget("optionForm", xmFormWidgetClass,
(Widget)pb, NULL, 0);
if (pbp->res_show_opts)
XtManageChild(pbp->option_form);
STARTARGS;
SETARG(XmNlabelString, pbp->res_opts_label);
SETARG(XmNalignment, XmALIGNMENT_BEGINNING);
SETARG(XmNtopAttachment, XmATTACH_FORM);
SETARG(XmNleftAttachment, XmATTACH_FORM);
pbp->opts_label_widget = XtCreateManagedWidget(DEF_OPTS_LABEL,
xmLabelWidgetClass,
pbp->option_form, ARGLIST);
STARTARGS;
SETARG(XmNscrollingPolicy, XmAUTOMATIC);
SETARG(XmNvisualPolicy, XmVARIABLE);
SETARG(XmNtopAttachment, XmATTACH_WIDGET);
SETARG(XmNtopWidget, pbp->opts_label_widget);
SETARG(XmNbottomAttachment, XmATTACH_FORM);
SETARG(XmNrightAttachment, XmATTACH_FORM);
SETARG(XmNleftAttachment, XmATTACH_FORM);
pbp->opts_sw_widget = XtCreateManagedWidget("optionSWindow",
xmScrolledWindowWidgetClass,
pbp->option_form, ARGLIST);
STARTARGS;
SETARG(XmNorientation, XmVERTICAL);
SETARG(XmNpacking, XmPACK_TIGHT);
SETARG(XmNadjustMargin, False);
SETARG(XmNadjustLast, False);
pbp->opts_rc_widget = XtCreateManagedWidget("optionRowC",
xmRowColumnWidgetClass,
pbp->opts_sw_widget, ARGLIST);
STARTARGS;
SETARG(XmNworkWindow, pbp->opts_rc_widget);
XtSetValues(pbp->opts_sw_widget, ARGLIST);
/*
* Set the scrolled window clip window background
* to the color same as the RC window background
*/
STARTARGS;
SETARG(XmNclipWindow, &clip);
XtGetValues(pbp->opts_sw_widget, ARGLIST);
if (clip) {
STARTARGS;
SETARG(XmNbackground, &bg);
XtGetValues(pbp->opts_rc_widget, ARGLIST);
STARTARGS;
SETARG(XmNbackground, bg);
XtSetValues(clip, ARGLIST);
}
CreateOptionArea(pbp, pbp->opts_rc_widget);
}
/**************************************************************************
*
* Function: CreateOptionArea
*
* Description: Creates the print job option area. This is the area
* where print job options are set (eg. number of copies).
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
static void CreateOptionArea(PuiPrintBoxPart *pbp, Widget parent)
{
register int i;
/*
* Create each option's UI
*/
for (i = 0; i < num_options; i++)
option_list[i].create_func(pbp, parent);
}
/**************************************************************************
*
* Function: CalculateMySize
*
* Description: Calculates the required overall size for this widget
* based on the size of the children.
*
* Parameters:
* pb (I) - this widget
* total_widthp (O) - required total width
* total_heightp (O) - required total width
*
* Return: none
*
**************************************************************************/
static void CalculateMySize(PuiPrintBoxWidget pb, int *total_widthp,
int *total_heightp)
{
PuiPrintBoxPart *pbp = &pb->printBox;
int plist_width, plist_height;
int option_width, option_height;
int work_width, work_height;
int control_width, control_height;
/*
* Get the dimensions of the filename/printer list form
*/
plist_width = WIDTH(pbp->pf_form);
plist_height = HEIGHT(pbp->pf_form);
/*
* Get the dimensions of the option area form
*/
if (pbp->res_show_opts) {
option_width = WIDTH(pbp->option_form);
option_height = HEIGHT(pbp->option_form);
}
/*
* If a work area has been specified get its dimensions
*/
if (pbp->work_area && XtIsManaged(pbp->work_area)) {
work_width = WIDTH(pbp->work_area);
work_height = HEIGHT(pbp->work_area) + VERT_SPACING(pb);
} else {
work_width = 0;
work_height = 0;
}
/*
* Determine the height and width of the control area
*/
control_width = plist_width;
if (pbp->res_show_opts) {
control_width += option_width + HORIZ_SPACING(pb);
control_height = option_height;
} else
control_height = plist_height;
/*
* Determine the overall dimensions of the widget excluding
* outer margins
*/
*total_widthp = MAX(work_width, control_width);
*total_widthp = MAX(WIDTH(pbp->action_form), *total_widthp);
*total_heightp = work_height + control_height + HEIGHT(pbp->action_form) +
VERT_SPACING(pb);
if (pbp->separator && XtIsManaged(pbp->separator))
*total_heightp += HEIGHT(pbp->separator) + VERT_SPACING(pb);
/*
* Add the outer margins to overall dimensions
*/
*total_widthp += 2 * MARGIN_WIDTH(pb);
*total_heightp += 2 * MARGIN_HEIGHT(pb);
}
/**************************************************************************
*
* Function: DoLayout
*
* Description: Positions and sizes the child widgets based on the
* widgets overall dimensions.
*
* Parameters:
* pb (I) - this widget
*
* Return: none
*
**************************************************************************/
static void DoLayout(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
int usable_width, usable_height;
int height_left, width_left;
Position x, y;
/*
* Determine the usable area, ie. overall dimensions
* minus outer margins
*/
width_left = usable_width = WIDTH(pb) - 2 * MARGIN_WIDTH(pb);
height_left = usable_height = HEIGHT(pb) - 2 * MARGIN_HEIGHT(pb);
/*
* Configure action area
*/
x = MARGIN_WIDTH(pb);
y = usable_height - HEIGHT(pbp->action_form) + MARGIN_HEIGHT(pb);
XtConfigureWidget(pbp->action_form, x, y,
usable_width,
HEIGHT(pbp->action_form),
BWIDTH(pbp->action_form));
height_left -= (HEIGHT(pbp->action_form) + VERT_SPACING(pb));
/*
* Configure separator
*/
if (pbp->separator && XtIsManaged(pbp->separator)) {
height_left -= (HEIGHT(pbp->separator) + VERT_SPACING(pb));
y -= (HEIGHT(pbp->separator) + VERT_SPACING(pb));
XtConfigureWidget(pbp->separator, 0, y,
usable_width + 2 * MARGIN_WIDTH(pb),
HEIGHT(pbp->separator),
BWIDTH(pbp->separator));
}
/*
* Configure work area
*/
x = MARGIN_WIDTH(pb);
y = MARGIN_HEIGHT(pb);
if (pbp->work_area && XtIsManaged(pbp->work_area)) {
if (height_left < HEIGHT(pbp->work_area))
y = height_left - HEIGHT(pbp->work_area) + MARGIN_HEIGHT(pb);
XtConfigureWidget(pbp->work_area, x, y,
usable_width,
HEIGHT(pbp->work_area),
BWIDTH(pbp->work_area));
height_left -= (HEIGHT(pbp->work_area) + VERT_SPACING(pb));
y += HEIGHT(pbp->work_area) + VERT_SPACING(pb);
}
/*
* Configure filename/printer list and option areas
*/
if (height_left > 0) {
x = MARGIN_WIDTH(pb);
if (XtIsRealized(pbp->pf_form))
XtMapWidget(pbp->pf_form);
if (pbp->res_show_opts) {
XtConfigureWidget(pbp->pf_form, x, y,
WIDTH(pbp->pf_form),
height_left,
BWIDTH(pbp->pf_form));
width_left -= (WIDTH(pbp->pf_form) + HORIZ_SPACING(pb));
x += WIDTH(pbp->pf_form) + HORIZ_SPACING(pb);
if (width_left > 0) {
if (XtIsRealized(pbp->option_form))
XtMapWidget(pbp->option_form);
XtConfigureWidget(pbp->option_form, x, y,
width_left,
height_left,
BWIDTH(pbp->option_form));
} else {
XtUnmapWidget(pbp->option_form);
}
} else {
XtConfigureWidget(pbp->pf_form, x, y,
usable_width, height_left,
BWIDTH(pbp->pf_form));
}
} else {
XtUnmapWidget(pbp->pf_form);
if (pbp->res_show_opts)
XtUnmapWidget(pbp->option_form);
}
}
/**************************************************************************
*
* Function: UpdateLabel
*
* Description: Sets the specified widget's label string based on the
* specified string resource. Used by the SetValues routine.
*
* Parameters:
* w (I) - widget whose label string is to be changed
* res_name (I) - resource name for the label
* labelp (I) - compound string specifying the label
*
* Return: none
*
**************************************************************************/
static void UpdateLabel(Widget w, String res_name, XmString *labelp)
{
Arg arg;
if (!w)
return;
XtSetArg(arg, res_name, *labelp);
XtSetValues(w, &arg, 1);
*labelp = NULL;
}
/**************************************************************************
*
* Function: SetPrinterList
*
* Description: Obtains a list of known printers, displays them in the
* printer selection list and selects an appropriate printer based
* on previous selections, default printer, etc. Also supervises
* construction of the printer specific options list.
*
* Parameters:
* pb (I) - this widget
*
* Return: 0 if no error occurred while setting the printer list.
* Otherwise, SLerrno is returned.
*
**************************************************************************/
static int SetPrinterList(PuiPrintBoxWidget pb)
{
register int i, len;
register int norm_spacing, def_spacing, max_spacing;
char buffer[MAX_LINE], *formal_name;
SLPrinterStruct *prptr;
XmString *printers_str, str1, str2;
PuiPrintBoxPart *pbp = &pb->printBox;
XmFontList flist;
DEFARGS(10);
/*
* Clear the default printer name, if any
*/
if (pbp->res_default_printer) {
free((char*)pbp->res_default_printer);
pbp->res_default_printer = NULL;
}
/*
* Destroy the printer specific options list, if any
*/
if (pbp->printer_options && pbp->res_num_printers) {
for (i = 0; i < pbp->res_num_printers; i++)
XtFree((char*)pbp->printer_options[i].option_str);
XtFree((char*)pbp->printer_options);
pbp->printer_options = NULL;
}
/*
* Get the list of known printers. We want to copy the list
* returned from the libspool function since it is a pointer
* to internal storage.
*/
FreePrinterList(pbp->res_printer_list, pbp->res_num_printers);
pbp->res_printer_list = NULL;
if (SLGetPrinterList(&prptr, &pbp->res_num_printers) < 0)
return SLerrno;
PrintSensitiveCB(NULL, (XtPointer)pbp, NULL);
if (!pbp->res_num_printers)
return 0;
pbp->res_printer_list = CopyPrinterList(prptr, pbp->res_num_printers);
/*
* Create the printer specific options list
*/
pbp->printer_options = (PuiPrinterOption*)XtMalloc(pbp->res_num_printers *
sizeof(PuiPrinterOption));
for (i = 0; i < pbp->res_num_printers; i++) {
pbp->printer_options[i].option_str =
ReadPrinterOptionsFile(pbp->res_printer_list[i].local_name);
pbp->printer_options[i].modified = False;
}
/*
* Calculate the horizontal spacing for the printer type
* labels in the printers list
*/
norm_spacing = MAX_PNAME + 4;
STARTARGS;
SETARG(XmNfontList, &flist);
XtGetValues(pbp->plist_widget, ARGLIST);
str1 = XmStringCreate(" ", PRINTER_CHARSET);
str2 = XmStringCreate(" ", DEF_PRINTER_CHARSET);
def_spacing = (int)((float)norm_spacing *
(float)XmStringWidth(flist, str1) /
(float)XmStringWidth(flist, str2) + 0.5);
max_spacing = (norm_spacing > def_spacing) ? norm_spacing: def_spacing;
XmStringFree(str1);
XmStringFree(str2);
/*
* Display the printers in the selection list
*/
printers_str = (pbp->res_num_printers > 0) ?
(XmString*)XtMalloc(pbp->res_num_printers*sizeof(XmString)): NULL;
for (i = 0, prptr = pbp->res_printer_list; i < pbp->res_num_printers;
i++, prptr++) {
if ((len = strlen(prptr->local_name)) > MAX_PNAME)
len = MAX_PNAME;
(void)bzero(buffer, MAX_LINE);
(void)memset(buffer, ' ', max_spacing);
(void)memcpy(buffer, prptr->local_name, len);
formal_name = (prptr->is_class) ? "Printer Class": prptr->formal_name;
if (prptr->is_def) {
(void)strncpy(buffer + def_spacing, formal_name, MAX_FORMALNAME);
printers_str[i] = XmStringCreate(buffer, DEF_PRINTER_CHARSET);
pbp->res_default_printer = strdup(prptr->local_name);
} else {
(void)strncpy(buffer + norm_spacing, formal_name, MAX_FORMALNAME);
printers_str[i] = XmStringCreate(buffer, PRINTER_CHARSET);
}
}
STARTARGS;
SETARG(XmNitems, printers_str);
SETARG(XmNitemCount, pbp->res_num_printers);
XtSetValues(pbp->plist_widget, ARGLIST);
for (i = 0; i < pbp->res_num_printers; i++)
XmStringFree(printers_str[i]);
if (pbp->res_num_printers > 0)
XtFree((char*)printers_str);
return 0;
}
/**************************************************************************
*
* Function: FreePrinterList
*
* Description: Frees the storage associated with the specified printer
* list.
*
* Parameters:
* printer_list (I) - array of printer info structures
* num_printers (I) - number of items in the array
*
* Return: none
*
**************************************************************************/
static void FreePrinterList(SLPrinterStruct *printer_list, int num_printers)
{
register SLPrinterStruct *prptr;
register int i;
if (!num_printers || !printer_list)
return;
for (i = 0, prptr = printer_list; i < num_printers; i++, prptr++) {
if (prptr->local_name) XtFree(prptr->local_name);
if (prptr->formal_name) XtFree(prptr->formal_name);
if (prptr->type) XtFree(prptr->type);
if (prptr->dev) XtFree(prptr->dev);
if (prptr->remote_host) XtFree(prptr->remote_host);
if (prptr->remote_name) XtFree(prptr->remote_name);
}
XtFree((char*)printer_list);
}
/**************************************************************************
*
* Function: CopyPrinterList
*
* Description: Makes a copy of the specified printer list.
*
* Parameters:
* printer_list (I) - array of printer structures to copy.
* num_printers (I) - number of printers in array
*
* Return: Pointer to copy of the printer list. If is the caller's
* responsibility to free this storage.
*
**************************************************************************/
static SLPrinterStruct* CopyPrinterList(SLPrinterStruct *printer_list,
int num_printers)
{
SLPrinterStruct *plist;
register SLPrinterStruct *orig_ptr, *new_ptr;
register int i;
if (!num_printers || !printer_list)
return NULL;
plist = (SLPrinterStruct*)XtMalloc(num_printers * sizeof(SLPrinterStruct));
for (i = 0, orig_ptr = printer_list, new_ptr = plist;
i < num_printers; i++, orig_ptr++, new_ptr++) {
new_ptr->local_name = (orig_ptr->local_name)?
XtNewString(orig_ptr->local_name): NULL;
new_ptr->formal_name = (orig_ptr->formal_name)?
XtNewString(orig_ptr->formal_name): NULL;
new_ptr->type = (orig_ptr->type)? XtNewString(orig_ptr->type): NULL;
new_ptr->dev = (orig_ptr->dev)? XtNewString(orig_ptr->dev): NULL;
new_ptr->remote_host = (orig_ptr->remote_host)?
XtNewString(orig_ptr->remote_host): NULL;
new_ptr->remote_name = (orig_ptr->remote_name)?
XtNewString(orig_ptr->remote_name): NULL;
new_ptr->is_def = orig_ptr->is_def;
new_ptr->is_class = orig_ptr->is_class;
new_ptr->is_networked = orig_ptr->is_networked;
}
return plist;
}
/**************************************************************************
*
* Function: SetFilenames
*
* Description: Sets the filenames in the filename widget based on the
* resource.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetFilenames(PuiPrintBoxPart *pbp)
{
if (pbp->res_filename)
XmTextFieldSetString(pbp->files_widget, pbp->res_filename);
else
XmTextFieldSetString(pbp->files_widget, "");
}
/**************************************************************************
*
* Function: SetPrinter
*
* Description: Selects the printer based on previous selections, resources
* defaults, etc.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetPrinter(PuiPrintBoxPart *pbp)
{
int printer_ind;
printer_ind = pbp->selected_printer_index;
if (printer_ind < 0) {
if (pbp->res_printer)
printer_ind = FindPrinter(pbp, pbp->res_printer);
}
if (printer_ind < 0) {
if (pbp->res_default_printer)
printer_ind = FindPrinter(pbp, pbp->res_default_printer);
}
if (printer_ind < 0)
printer_ind = 0;
XmListSelectPos(pbp->plist_widget, printer_ind + 1, True);
XmListSetBottomPos(pbp->plist_widget, printer_ind + 1);
}
/**************************************************************************
*
* Function: PrintSensitiveCB
*
* Description: Checks whether there are printers available and at least
* one filename has been specified. If these conditions are true
* the print button is made sensitive, otherwise it is made in-
* sensitive.
*
* Parameters:
* w (I) - widget that invoked this callback
* client_data (I) - this widget's instance part
* call_data (I) - unused
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void PrintSensitiveCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxPart *pbp = (PuiPrintBoxPart*)client_data;
char *str;
register char *sptr;
Boolean sensitive = False;
if (pbp->res_num_printers) {
if (pbp->res_job_type == PuiPRINTJOB_FILENAME) {
str = XmTextFieldGetString(pbp->files_widget);
for (sptr = str; *sptr; sptr++) {
if (!isspace((int)*sptr) && !iscntrl((int)*sptr)) {
sensitive = True;
break;
}
}
XtFree((char*)str);
} else
sensitive = True;
}
XtSetSensitive(pbp->printb_widget, sensitive);
}
/**************************************************************************
*
* Function: FindPrinter
*
* Description: Linearly searches the printer list looking for
* the specified printer name.
*
* Parameters:
* pbp (I) - this widget's instance part
* printers (I) - list of printers
*
* Return: Returns the list index if the printer is found. Returns -1
* if the printer is not found.
*
**************************************************************************/
static int FindPrinter(PuiPrintBoxPart *pbp, char *pname)
{
register int i;
for (i = 0; i < pbp->res_num_printers; i++)
if (!strcmp(pbp->res_printer_list[i].local_name, pname))
break;
return ((i == pbp->res_num_printers) ? -1: i);
}
/**************************************************************************
*
* Function: PrinterSelectedCB
*
* Description: Called when a printer from the printer list is single
* clicked (selection) or double clicked (action).
*
* Parameters:
* w (I) - the invoking widget
* client_data (I) - this widget
* call_data (I) - list callback struct
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void PrinterSelectedCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
PuiPrintBoxCallbackStruct pb_cb;
XmListCallbackStruct *lcb = (XmListCallbackStruct*)call_data;
XtCallbackList callback_list;
register int pind;
register char *pname;
/*
* If there are no printers in the list there is nothing to do
*/
if (pbp->res_num_printers == 0)
return;
/*
* Set a variable for convenience
*/
pind = pbp->selected_printer_index;
/*
* Update the printer option string list if there
* is a currently selected printer
*/
if (pind >= 0)
UpdatePrinterOption(pb, &pbp->printer_options[pind]);
/*
* Kill the options panel if an options panel instance exists for the
* old printer. Do not kill the options panel if the original printer
* is the same as the newly selected printer.
*/
if (pind >= 0 && pbp->res_show_optionsbutton && pbp->option_panels &&
pbp->option_panels[pind] &&
(pbp->selected_printer_index != lcb->item_position - 1))
_PuiOptionPanelKill(pbp->option_panels[pind], True);
/*
* Set the selected printer variable
*/
pind = pbp->selected_printer_index = lcb->item_position - 1;
/*
* Set a variable for the printer name
*/
pname = pbp->res_printer_list[pind].local_name;
/*
* Update the UI with the new printer's options
*/
if (pbp->res_spec_opts)
XtFree(pbp->res_spec_opts);
pbp->res_spec_opts = XtNewString(pbp->printer_options[pind].option_str);
SetOptionPrinterSpecific(pbp);
/*
* If we want option panels, determine if one exists for this printer
* and create the option panel instance if it has not already been
* created and register callbacks for it. We also set the options
* button sensitivity accordingly.
*/
if (pbp->res_show_optionsbutton && pbp->option_panels) {
if (_PuiOptionPanelExists(pname)) {
if (!pbp->option_panels[pind]) {
pbp->option_panels[pind] =
_PuiOptionPanelCreate(pbp->action_form, pname, True);
if (pbp->option_panels[pind]) {
_PuiOptionPanelSetCallback(pbp->option_panels[pind],
PuiNoptionPanelErrorCallback,
OptionErrorCB, (XtPointer)pb);
_PuiOptionPanelSetCallback(pbp->option_panels[pind],
PuiNoptionPanelMapCallback,
OptionMappedCB, (XtPointer)pb);
_PuiOptionPanelSetCallback(pbp->option_panels[pind],
PuiNoptionPanelDeathCallback,
OptionDeathCB, (XtPointer)pb);
_PuiOptionPanelSetCallback(pbp->option_panels[pind],
PuiNoptionPanelDataCallback,
OptionDataCB, (XtPointer)pb);
}
}
if (pbp->option_panels[pind])
XtSetSensitive(pbp->optionsb_widget, True);
} else {
if (pbp->option_panels[pind]) {
_PuiOptionPanelDestroy(pbp->option_panels[pind]);
pbp->option_panels[pind] = NULL;
}
XtSetSensitive(pbp->optionsb_widget, False);
}
XFlush(XtDisplay((Widget)pb));
}
/*
* Call any printer selection callbacks
*/
InitCallback(&pb_cb);
pb_cb.reason = (lcb->reason == XmCR_DEFAULT_ACTION) ? PuiCR_PR_ACTION:
PuiCR_PR_SELECT;
pb_cb.selected_printer = pname;
pb_cb.selected_position = lcb->item_position;
callback_list = (lcb->reason == XmCR_DEFAULT_ACTION) ?
pbp->res_pr_action_callback: pbp->res_pr_select_callback;
XtCallCallbackList(w, callback_list, (XtPointer)&pb_cb);
}
/**************************************************************************
*
* Function: ActionAreaCB
*
* Description: All action area push buttons call this routine. This
* routine executes the appropriate callback list for the specified
* button. Note that the print button calls user specified callbacks
* before the internal print callback so that users can get in and
* change things before printing.
*
* Parameters:
* w (I) - widget ID of button invoking this routine
* client_data (I) - printBox widget ID
* call_data (I) - XmPushButtonCallbackStruct
*
* Return: none
*
**************************************************************************/
static void ActionAreaCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxCallbackStruct pb_cb;
int button_id;
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
XmAnyCallbackStruct *cb = (XmAnyCallbackStruct*)call_data;
DEFARGS(5);
/*
* Initialize the callback struct and copy the X event that
* triggered the callback and set the unused fields to sane values.
*/
InitCallback(&pb_cb);
pb_cb.event = cb->event;
/*
* Set the reason based on the button pushed
*/
STARTARGS;
SETARG(XmNuserData, &button_id);
XtGetValues(w, ARGLIST);
switch (button_id) {
case PuiPRINTBOX_PRINT_BUTTON:
pb_cb.reason = PuiCR_PRINT;
XtCallCallbackList((Widget)pb, pb->printBox.res_print_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_USER1_BUTTON:
pb_cb.reason = PuiCR_USER1;
XtCallCallbackList((Widget)pb, pb->printBox.res_user1_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_USER2_BUTTON:
pb_cb.reason = PuiCR_USER2;
XtCallCallbackList((Widget)pb, pb->printBox.res_user2_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_USER3_BUTTON:
pb_cb.reason = PuiCR_USER3;
XtCallCallbackList((Widget)pb, pb->printBox.res_user3_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_USER4_BUTTON:
pb_cb.reason = PuiCR_USER4;
XtCallCallbackList((Widget)pb, pb->printBox.res_user4_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_CANCEL_BUTTON:
pb_cb.reason = PuiCR_CANCEL;
XtCallCallbackList((Widget)pb, pb->printBox.res_cancel_callback,
(XtPointer)&pb_cb);
break;
case PuiPRINTBOX_HELP_BUTTON:
pb_cb.reason = PuiCR_HELP;
XtCallCallbackList((Widget)pb, pb->printBox.res_help_callback,
(XtPointer)&pb_cb);
break;
}
}
/**************************************************************************
*
* Function: SubmitPrintJobCB
*
* Description: Handles the submittal of a print job. Note that this
* routine simply returns if the application is handling printing.
* Also this callback is called after any user registered Print button
* callbacks so that the user can change any resource of this widget
* (eg. print buffer) before the actual printing routine is run.
*
* Parameters:
* w (I) - widget that invoked this callback
* client_data (I) - this widget
* call_data (I) - not used
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SubmitPrintJobCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
SLPrintJob *job_info;
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
PuiPrintBoxCallbackStruct pb_cb;
register int i;
char *filenames, *exp_filenames, *pname;
/*
* First make sure that user wants us to do printing
*/
if (pbp->res_print_policy == PuiAPPLICATION_PRINTING)
return;
/*
* Clear spooler specific option string
*/
ClearPrinterOptions(pbp);
/*
* Get the option settings
*/
for (i = 0; i < num_options; i++)
option_list[i].get_func(pbp);
/*
* Set the printer name
*/
pname = pbp->res_printer_list[pbp->selected_printer_index].local_name;
/*
* Submit the print job
*/
switch (pbp->res_job_type) {
case PuiPRINTJOB_DESCRIPTOR:
job_info = SLSubmitJobFd(pbp->res_fd, pname,
pbp->num_copies,
pbp->copy_file,
pbp->mail,
pbp->job_title,
pbp->options);
break;
case PuiPRINTJOB_BUFFER:
job_info = SLSubmitJobBuf(pbp->res_buffer,
(size_t)pbp->res_bufsize,
pname,
pbp->num_copies,
pbp->copy_file,
pbp->mail,
pbp->job_title,
pbp->options);
break;
case PuiPRINTJOB_FILENAME:
filenames = XmTextFieldGetString(pbp->files_widget);
exp_filenames = _PuiExpandFilenames(filenames);
XtFree((char*)filenames);
job_info = SLSubmitJob(exp_filenames, pname,
pbp->num_copies,
pbp->copy_file,
pbp->mail,
pbp->job_title,
pbp->options);
XtFree((char*)exp_filenames);
break;
default:
break;
}
/*
* If job_info != NULL call the callbacks for job info otherwise
* call the callbacks for error condition.
*/
if (job_info) {
InitCallback(&pb_cb);
pb_cb.reason = PuiCR_JOB_INFO;
pb_cb.job_info = job_info;
XtCallCallbackList((Widget)pb, pbp->res_jobinfo_callback,
(XtPointer)&pb_cb);
} else
HandleError(pb, SLerrno);
}
/**************************************************************************
*
* Function: OptionButtonCB
*
* Description: Called when the options button is pressed. The function
* attempts to exec an option panel program.
*
* Parameters:
* w (I) - widget ID of button invoking this routine
* client_data (I) - this widget
* call_data (I) - XmPushButtonCallbackStruct
*
* Return: none
*
**************************************************************************/
static void OptionButtonCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
PuiOptionPanelArgs args;
XtArgVal fnames, optstr;
if (pbp->option_panels &&
pbp->option_panels[pbp->selected_printer_index]) {
/*
* Set a busy cursor
*/
SetCursor(pb, PuiCursorBusy);
/*
* Build the command line arguments for the option panel program
*/
args.userName = pbp->user_name;
SynthGetFilename((Widget)pb, offset(printBox.res_filename), &fnames);
args.filenames = (char*)fnames;
SynthGetOptionPrinterSpecific((Widget)pb,
offset(printBox.res_spec_opts), &optstr);
args.options = (char*)optstr;
args.clientXtOptions = NULL;
args.numClientXtOptions = 0;
/*
* Launch the program and clean up
*/
_PuiOptionPanelExec(pbp->option_panels[pbp->selected_printer_index],
&args);
if (fnames) XtFree((char*)fnames);
if (optstr) XtFree((char*)optstr);
/*
* Disable the type-in options field
*/
SetTextFieldSensitivity(pbp, pbp->spec_options_widget, False);
}
}
/**************************************************************************
*
* Function: OptionDataCB
*
* Description: Called when a printer option panel has an option string
* available. This occurs when either the apply or OK button is
* pressed on the option panel.
*
* Parameters:
* panel (I) - pointer to the option panel structure for the panel
* client_data (I) - this widget
* cb (I) - callback information structure
*
* Return: None
*
**************************************************************************/
static void OptionDataCB(PuiOptionPanel *panel, XtPointer client_data,
PuiOptionPanelCallbackStruct *cb)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
/*
* Make sure the busy cursor is cleared (in case we didn't detect the
* option panel mapping).
*/
SetCursor(pb, PuiCursorNormal);
/*
* Put the options string in the type-in field
*/
if (pbp->res_spec_opts)
XtFree(pbp->res_spec_opts);
pbp->res_spec_opts = XtNewString(cb->options);
SetOptionPrinterSpecific(pbp);
}
/**************************************************************************
*
* Function: OptionMappedCB
*
* Description: Called when a printer option panel is mapped to the screen
* for the first time.
*
* Parameters:
* panel (I) - pointer to the option panel structure for the panel
* client_data (I) - this widget
* cb (I) - callback information structure
*
* Return: None
*
**************************************************************************/
static void OptionMappedCB(PuiOptionPanel *panel, XtPointer client_data,
PuiOptionPanelCallbackStruct *cb)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
/*
* Clear the busy cursor
*/
SetCursor(pb, PuiCursorNormal);
}
/**************************************************************************
*
* Function: OptionErrorCB
*
* Description: Called when a printer option panel has encountered an
* execution error.
*
* Parameters:
* panel (I) - pointer to the option panel structure for the panel
* client_data (I) - this widget
* cb (I) - callback information structure
*
* Return: None
*
**************************************************************************/
static void OptionErrorCB(PuiOptionPanel *panel, XtPointer client_data,
PuiOptionPanelCallbackStruct *cb)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxCallbackStruct pb_cb;
InitCallback(&pb_cb);
pb_cb.reason = PuiCR_OPT_ERROR;
pb_cb.error_code = cb->errorCode;
XtCallCallbackList((Widget)pb, pb->printBox.res_opt_error_callback,
(XtPointer)&pb_cb);
}
/**************************************************************************
*
* Function: OptionDeathCB
*
* Description: Called when a printer option panel terminates execution.
* This function will be called either when the option panel is
* killed programmatically or when the OK or cancel button is pressed.
*
* Parameters:
* panel (I) - pointer to the option panel structure for the panel
* client_data (I) - this widget
* cb (I) - callback information structure
*
* Return: None
*
**************************************************************************/
static void OptionDeathCB(PuiOptionPanel *panel, XtPointer client_data,
PuiOptionPanelCallbackStruct *cb)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
/*
* Make sure the busy cursor is cleared (in case we didn't detect the
* option panel mapping).
*/
SetCursor(pb, PuiCursorNormal);
/*
* Enable the type-in options field
*/
SetTextFieldSensitivity(pbp, pbp->spec_options_widget, True);
}
/**************************************************************************
*
* Function: QueryForSaveCB
*
* Description: Called when the Save button is pressed. Function pops up
* a dialog which performs two jobs. Job one is to allow privilleged
* users the ability to save default options for a printer. The
* second job is to allow users to select among the printer's whose
* printer specific options have been modified.
*
* Parameters:
* w (I) - widget ID of button invoking this routine
* client_data (I) - this widget
* call_data (I) - XmPushButtonCallbackStruct
*
* Return: none
*
**************************************************************************/
static void QueryForSaveCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
XmString printer_str;
register int i;
int num_modified;
/*
* Do not put up the dialog if it is already up
*/
if (XtIsManaged(pbp->save_dialog_widget))
return;
/*
* Update the printer option string list if there
* is a currently selected printer
*/
if (pbp->selected_printer_index >= 0)
UpdatePrinterOption(pb,
&pbp->printer_options[pbp->selected_printer_index]);
/*
* Now cycle through the array of printer specific options. Add
* the printer to the list if its options have been marked as
* modified. If no printers have modified options, add the current
* printer. If there is no current printer we leave the list
* empty. Note that we do not include printer classes on the list
* since printer options have no meaning for a printer class. Note
* also that items are added in a selected state
*/
XmListDeleteAllItems(pbp->save_list_widget);
num_modified = 0;
for (i = 0; i < pbp->res_num_printers; i++) {
if (pbp->printer_options[i].modified &&
!pbp->res_printer_list[i].is_class) {
printer_str =
XmStringCreateLocalized(pbp->res_printer_list[i].local_name);
XmListAddItemUnselected(pbp->save_list_widget, printer_str, 0);
XmListSelectPos(pbp->save_list_widget, 0, False);
XmStringFree(printer_str);
num_modified++;
}
}
if (!num_modified && pbp->selected_printer_index >= 0 &&
!pbp->res_printer_list[pbp->selected_printer_index].is_class) {
printer_str = XmStringCreateLocalized(
pbp->res_printer_list[pbp->selected_printer_index].local_name);
XmListAddItemUnselected(pbp->save_list_widget, printer_str, 0);
XmListSelectPos(pbp->save_list_widget, 0, False);
XmStringFree(printer_str);
}
/*
* Pop up the dialog
*/
XtManageChild(pbp->save_dialog_widget);
}
/**************************************************************************
*
* Function: SaveOptionsCB
*
* Description: Supervises the saving of the printer specific and spooler
* options.
*
* Parameters:
* w (I) - widget ID of button invoking this routine
* client_data (I) - this widget
* call_data (I) - XmPushButtonCallbackStruct
*
* Return: none
*
**************************************************************************/
static void SaveOptionsCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxWidget pb = (PuiPrintBoxWidget)client_data;
PuiPrintBoxPart *pbp = &pb->printBox;
XmPushButtonCallbackStruct *cb = (XmPushButtonCallbackStruct*)call_data;
PuiPrintBoxCallbackStruct pb_cb;
XmString *plist_str;
int i, pind, num_plist, save_type;
char *pname;
DEFARGS(10);
/*
* If apply button pressed, pop down dialog. We need to do this
* explicitly since the apply callback does not trigger the
* autoUnamange callback.
*/
if (cb->reason == XmCR_APPLY)
XtUnmanageChild(pbp->save_dialog_widget);
/*
* Save the spooler options. If the write fails, send
* out the error to the error callback list.
*/
if (WriteSpoolerOptionsFile(pb) < 0) {
HandleError(pb, SLerrno);
return;
}
/*
* Get the selected printers in the save options list
*/
STARTARGS;
SETARG(XmNselectedItems, &plist_str);
SETARG(XmNselectedItemCount, &num_plist);
XtGetValues(pbp->save_list_widget, ARGLIST);
/*
* Determine whether we are saving printer specific
* options for just this user or for all users
*/
save_type = (cb->reason == XmCR_OK)? SL_SAVE_USER: SL_SAVE_DEFAULT;
/*
* For each selected printer save the options and mark
* the corresponding entries in the printer options list
* as unmodified.
*/
for (i = 0; i < num_plist; i++) {
if (!XmStringGetLtoR(plist_str[i], XmFONTLIST_DEFAULT_TAG, &pname))
continue;
if ((pind = FindPrinter(pbp, pname)) < 0)
continue;
if (WritePrinterOptionsFile(pname,
pbp->printer_options[pind].option_str, save_type) < 0) {
HandleError(pb, SLerrno);
XtFree(pname);
return;
}
pbp->printer_options[pind].modified = False;
XtFree(pname);
}
/*
* Now call the folks who want to know that we successfully
* saved the options files. Copy the X event that triggered
* the callback and set the unused fields to sane values.
*/
InitCallback(&pb_cb);
pb_cb.reason = PuiCR_SAVE;
pb_cb.event = cb->event;
XtCallCallbackList((Widget)pb, pbp->res_save_callback, (XtPointer)&pb_cb);
}
/**************************************************************************
*
* Function: CreateSaveDialog
*
* Description: Creates the options saving dialog. This dialog queries
* the user for the printers for which options are to be saved and
* if user is privilleged, allows saving of printer default options
* for all users.
*
* Parameters:
* pb (I) - this widget
*
* Return: Created dialog widget
*
**************************************************************************/
static Widget CreateSaveDialog(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
Widget dialog, form, label;
DEFARGS(20);
/*
* Create the dialog. Note that the action area button labels
* depend on who we are. If we are root or lp we add the Apply button
* and use that for saving printer settings for all users.
*/
STARTARGS;
SETARG(XmNdialogTitle, pbp->res_savedlg_title_label);
SETARG(XmNcancelLabelString, pbp->res_savedlg_cancelb_label);
if (strcmp(pbp->user_name, "root") && strcmp(pbp->user_name, "lp")) {
SETARG(XmNokLabelString, pbp->res_savedlg_saveb_label);
dialog = XmCreatePromptDialog((Widget)pb, "saveDialog", ARGLIST);
} else {
SETARG(XmNokLabelString, pbp->res_savedlg_userb_label);
SETARG(XmNapplyLabelString, pbp->res_savedlg_allb_label);
dialog = XmCreatePromptDialog((Widget)pb, "saveDialog", ARGLIST);
XtManageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_APPLY_BUTTON));
}
/*
* Remove the canned dialog message. Remove the separator if the
* parent dialog's separator has been unmanaged. And remove the help
* button since it is not needed and makes the dialog too wide.
*/
XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_SELECTION_LABEL));
XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_TEXT));
if (XtIsManaged(pbp->separator) == False)
XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_SEPARATOR));
/*
* Create a form as a child of the dialog
*/
form = XtCreateManagedWidget("saveForm", xmFormWidgetClass,
dialog, NULL, 0);
/*
* Create a title for the printer list
*/
STARTARGS;
SETARG(XmNleftAttachment, XmATTACH_FORM);
SETARG(XmNtopAttachment, XmATTACH_FORM);
SETARG(XmNlabelString, pbp->res_savedlg_msg_label);
pbp->save_msg_widget = XtCreateManagedWidget("saveMessage",
xmLabelWidgetClass, form, ARGLIST);
/*
* Create the list
*/
STARTARGS;
SETARG(XmNvisibleItemCount, 3);
SETARG(XmNselectionPolicy, XmMULTIPLE_SELECT);
SETARG(XmNleftAttachment, XmATTACH_FORM);
SETARG(XmNrightAttachment, XmATTACH_FORM);
SETARG(XmNtopAttachment, XmATTACH_WIDGET);
SETARG(XmNtopWidget, pbp->save_msg_widget);
SETARG(XmNbottomAttachment, XmATTACH_FORM);
pbp->save_list_widget = XmCreateScrolledList(form, "saveList", ARGLIST);
XtManageChild(pbp->save_list_widget);
/*
* Register callbacks
*/
XtAddCallback(dialog, XmNokCallback, SaveOptionsCB, (XtPointer)pb);
XtAddCallback(dialog, XmNapplyCallback, SaveOptionsCB, (XtPointer)pb);
return dialog;
}
/**************************************************************************
*
* Function: ClearPrinterOptions
*
* Description: Deallocates storage for the spooler specific options
* string.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void ClearPrinterOptions(PuiPrintBoxPart *pbp)
{
if (pbp->options) {
free((char*)pbp->options);
pbp->options = NULL;
}
}
/**************************************************************************
*
* Function: AddPrinterOptions
*
* Description: Adds a specified option to the spooler specific options
* string.
*
* Parameters:
* pbp (I) - this widget's instance part
* option (I) - option to add to string.
*
* Return: none
*
**************************************************************************/
static void AddPrinterOptions(PuiPrintBoxPart *pbp, char *option)
{
int len;
if (!pbp->options)
pbp->options = strdup(option);
else {
len = strlen(pbp->options) + strlen(option) + 5;
pbp->options = (char*)realloc(pbp->options, len);
(void)strcat(pbp->options, " ");
(void)strcat(pbp->options, option);
}
}
/**************************************************************************
*
* Function: SetStringValue
*
* Description: Handles the SetValues method string setting operations.
*
* Parameters:
* cstrp (I,O) - current string
* rstrp (I,O) - requested string
* nstrp (I,O) - new string
*
* Return: none
*
**************************************************************************/
static void SetStringValue(char **cstrp, char **rstrp, char **nstrp)
{
if (*nstrp)
*nstrp = XtNewString(*nstrp);
XtFree((char*)*cstrp);
*cstrp = *rstrp = NULL;
}
/**************************************************************************
*
* Function: DestroyParentCB
*
* Description: Destroys the parent of a widget. Used by the dialog
* convenience function.
*
* Parameters:
* w (I) - invoking widget
* client_data (I) - not used
* call_data (I) - not used
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void DestroyParentCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
XtDestroyWidget(XtParent(w));
}
/**************************************************************************
*
* Function: UnmanageCB
*
* Description: Unmanages the printBox if it is a dialog. Invoked if the
* autoUnmanage resource for bulletin board is true.
*
* Parameters:
* w (I) - invoking widget
* client_data (I) - widget to unmanage
* call_data (I) - not used
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void UnmanageCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
XtUnmanageChild((Widget)client_data);
}
/**************************************************************************
*
* Function: SetOptionsSize
*
* Description: Computes the initial size for the options scrolled window
* so that the window displays all options without the need to scroll.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetOptionsSize(PuiPrintBoxPart *pbp)
{
int dw, dh;
Dimension width, fwidth, fheight;
Dimension sb_space, sb_size;
Widget sb, cwin;
DEFARGS(15);
/*
* If no option section requested or if the widget is
* realized we don't need to calc anything
*/
if (!pbp->res_show_opts || XtIsRealized(pbp->option_form))
return;
/*
* Get the scrolled window clip window and the scrollbar dims
*/
STARTARGS;
SETARG(XmNclipWindow, &cwin);
SETARG(XmNverticalScrollBar, &sb);
SETARG(XmNspacing, &sb_space);
XtGetValues(pbp->opts_sw_widget, ARGLIST);
/*
* Calc space dedicated to scrollbar and size of clip window
* versus size of total size of window being viewed
*/
sb_size = WIDTH(sb) + sb_space;
if ((dw = WIDTH(pbp->opts_rc_widget) - WIDTH(cwin) - sb_size) < 0)
dw = 0;
if ((dh = HEIGHT(pbp->opts_rc_widget) - HEIGHT(cwin) - sb_size) < 0)
dh = 0;
width = WIDTH(pbp->opts_sw_widget) + dw;
fwidth = WIDTH(pbp->option_form);
fheight = HEIGHT(pbp->option_form);
if (width > fwidth)
fwidth = width;
fheight += dh;
XtResizeWidget(pbp->option_form, fwidth, fheight,
BWIDTH(pbp->option_form));
}
/**************************************************************************
*
* Function: SetPrinterListSize
*
* Description: Computes the initial size for the printer list widget.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetPrinterListSize(PuiPrintBoxPart *pbp)
{
Dimension sb_space, sb_size;
Dimension width;
Widget sb;
DEFARGS(10);
if (XtIsRealized(pbp->pf_form))
return;
/*
* Get the size of the scrollbar and any margin. We
* need to do this so that if there is no scrollbar
* yet, when we resize and get one we do not obscure
* list text
*/
STARTARGS;
SETARG(XmNverticalScrollBar, &sb);
SETARG(XmNspacing, &sb_space);
XtGetValues(XtParent(pbp->plist_widget), ARGLIST);
sb_size = WIDTH(sb) + sb_space;
/*
* Get diemsnions of newly grown list
*/
width = WIDTH(pbp->plist_widget);
/*
* Based on the presence of a list scrollbar and the width of
* the new list calculate what the list should be resized to.
* We never want to let the scrolled list width be less than the
* filename/printer list form width.
*/
width += sb_size;
if (width < WIDTH(pbp->pf_form))
width = WIDTH(pbp->pf_form);
/*
* Set the proper size
*/
XtResizeWidget(pbp->pf_form, width, HEIGHT(pbp->pf_form),
BWIDTH(pbp->pf_form));
}
/**************************************************************************
*
* Function: SetActionAreaSize
*
* Description: Sets the width of the action form in the case where the
* buttons are to be centered.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetActionAreaSize(PuiPrintBoxPart *pbp)
{
if (pbp->res_button_placement == PuiBUTTONS_CENTER)
XtResizeWidget(pbp->action_form, WIDTH(pbp->action_rc),
HEIGHT(pbp->action_form), BWIDTH(pbp->action_form));
}
/**************************************************************************
*
* Function: HandleError
*
* Description: Processes the detection of a libspool error condition.
* The function creates the appropriate error callback structure and
* calls the functions on the widget's error callback list.
*
* Parameters:
* pb (I) - this widget
* err_code (I) - SLerrno value
*
* Return: none
*
**************************************************************************/
static void HandleError(PuiPrintBoxWidget pb, int err_code)
{
PuiPrintBoxCallbackStruct pb_cb;
InitCallback(&pb_cb);
pb_cb.reason = PuiCR_ERROR;
pb_cb.error_code = err_code;
XtCallCallbackList((Widget)pb, pb->printBox.res_error_callback,
(XtPointer)&pb_cb);
}
/**************************************************************************
*
* Function: InitTextFieldColors
*
* Description: Sets the instance part fields for text field foreground,
* background and shadow colors for use in settings the text field
* to sensitive and insensitive states. We want to have the text
* field foreground and background color change when the text field
* is made insensitive.
*
* Parameters:
* pb (I) - this widget
*
* Return: none
*
**************************************************************************/
static void InitTextFieldColors(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
register int n;
Arg args[5];
/*
* Get the sensitive foreground and background color of a
* representative test field widget, the filename list widget
*/
n = 0;
XtSetArg(args[n], XmNforeground, &pbp->tfield_sensitive.foreground); n++;
XtSetArg(args[n], XmNbackground, &pbp->tfield_sensitive.background); n++;
XtGetValues(pbp->files_widget, args, n);
/*
* Compute the text field shadow colors
* for the sensitive and insensitive states
*/
XmGetColors(XtScreen(pb), pb->core.colormap,
pbp->tfield_sensitive.background,
NULL,
&pbp->tfield_sensitive.tshadow,
&pbp->tfield_sensitive.bshadow,
NULL);
XmGetColors(XtScreen(pb), pb->core.colormap,
pbp->tfield_insensitive.background,
NULL,
&pbp->tfield_insensitive.tshadow,
&pbp->tfield_insensitive.bshadow,
NULL);
}
/**************************************************************************
*
* Function: SetTextFieldSensitivity
*
* Description: Sets the sensitivity of the specified text field widget.
* The editability as well as the foreground and background colors
* of the field are changed according to the specified state.
*
* Parameters:
* pbp (I) - this widget's instance part
* field (I) - widget ID of text field whose sensitivity is to be
* changed.
* sensitive (I) - True or False.
*
* Return: none
*
**************************************************************************/
static void SetTextFieldSensitivity(PuiPrintBoxPart *pbp, Widget field,
Boolean sensitive)
{
Arg args[10];
register int n = 0;
PuiPrintBoxFieldColors colors;
XtSetArg(args[n], XmNeditable, sensitive); n++;
if (sensitive)
colors = pbp->tfield_sensitive;
else
colors = pbp->tfield_insensitive;
XtSetArg(args[n], XmNforeground, colors.foreground); n++;
XtSetArg(args[n], XmNbackground, colors.background); n++;
XtSetArg(args[n], XmNtopShadowColor,colors.tshadow); n++;
XtSetArg(args[n], XmNbottomShadowColor, colors.bshadow); n++;
XtSetValues(field, args, n);
}
/**************************************************************************
*
* Function: SetCursor
*
* Description: Sets the cursor to the state specified.
*
* Parameters:
* pb (I) - this widget
* state (I) - one of PuiCursorBusy or PuiCursorNormal
*
* Return: none
*
**************************************************************************/
static void SetCursor(PuiPrintBoxWidget pb, PuiCursorState state)
{
PuiPrintBoxPart *pbp = &pb->printBox;
switch (state) {
case PuiCursorBusy:
XDefineCursor(XtDisplay((Widget)pb), XtWindow((Widget)pb),
pbp->res_busy_cursor);
break;
case PuiCursorNormal:
XUndefineCursor(XtDisplay((Widget)pb), XtWindow((Widget)pb));
break;
}
XFlush(XtDisplay((Widget)pb));
}
/**************************************************************************
*
* Function: ReadSpoolerOptionsFile
*
* Description: Reads the spooling system options file, if any, and sets
* the UI accordingly.
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void ReadSpoolerOptionsFile(PuiPrintBoxPart *pbp)
{
SLSysVSpoolerOptionsStruct *spooler_opts;
/*
* Read the spooler options file
*/
if (SLSysVGetSpoolerOptions(&spooler_opts) < 0)
return;
/*
* Set the UI accordingly
*/
if (spooler_opts->copy) {
pbp->res_copy = True;
SetOptionJobHandling(pbp);
}
if (spooler_opts->mail)
pbp->res_mail = True;
if (spooler_opts->message)
pbp->res_message = True;
if (spooler_opts->mail || spooler_opts->message)
SetOptionCompletion(pbp);
if (spooler_opts->title) {
if (pbp->res_job_title)
XtFree(pbp->res_job_title);
pbp->res_job_title = XtNewString(spooler_opts->title);
SetOptionBanner(pbp);
}
}
/**************************************************************************
*
* Function: WriteSpoolerOptionsFile
*
* Description: Writes the spooler options file based on the state of
* the PrintBox UI.
*
* Parameters:
* pb (I) - this widget
*
* Return: 0 if success and -1 if failure.
*
**************************************************************************/
static int WriteSpoolerOptionsFile(PuiPrintBoxWidget pb)
{
PuiPrintBoxPart *pbp = &pb->printBox;
SLSysVSpoolerOptionsStruct spooler_opts;
XtArgVal val;
int retv;
/*
* Fill in the spooler options struct from the UI.
*
* Note that we do not care about the number of copies.
* The number of copies would cause more harm than good if it were
* placed in the rc file. Accidently setting 500 copies could have
* interesting results for future print jobs. We also do not write
* the printer name since this would raise confusion between the
* system default printer and the glprc printer.
*/
SynthGetOptionJobHandling((Widget)pb, offset(printBox.res_copy), &val);
spooler_opts.copy = (val)? 1: 0;
SynthGetOptionCompletion((Widget)pb, offset(printBox.res_mail), &val);
spooler_opts.mail = (val)? 1: 0;
SynthGetOptionCompletion((Widget)pb, offset(printBox.res_message), &val);
spooler_opts.message = (val)? 1: 0;
SynthGetOptionBanner((Widget)pb, offset(printBox.res_job_title), &val);
spooler_opts.title = (char*)val;
spooler_opts.suppress_id = 0; /* Not supported at widget level */
/*
* Write the file
*/
retv = SLSysVSaveSpoolerOptions(&spooler_opts);
/*
* Free any allocated storage
*/
if (spooler_opts.title)
XtFree(spooler_opts.title);
return retv;
}
/**************************************************************************
*
* Function: ReadPrinterOptionsFile
*
* Description: Reads the printer specific options, if any, for the
* specified printer
*
* Parameters:
* printer_name (I) - name of printer whose options are desired
*
* Return: Printer specific option string or empty string "" if no printer
* options found. It is the caller's responsibility to free the
* storage allocated by this function.
*
**************************************************************************/
static char* ReadPrinterOptionsFile(char *printer_name)
{
char *option_str;
if (SLSysVGetPrinterOptions(printer_name, &option_str) < 0 ||
option_str == NULL)
return XtNewString("");
return XtNewString(option_str);
}
/**************************************************************************
*
* Function: WritePrinterOptionsFile
*
* Description: Writes the printer specific option file for the specified
* printer.
*
* Parameters:
* printer_name (I) - name of printer whose options are to be saved.
* option_str (I) - printer specific option string.
* save_type (I) - what type of options to save (i.e. SL_SAVE_USER or
* SL_SAVE_DEFAULT).
*
* Return: 0 if successfull, -1 if not.
*
**************************************************************************/
static int WritePrinterOptionsFile(char *printer_name, char *option_str,
int save_type)
{
return SLSysVSavePrinterOptions(printer_name, option_str, save_type);
}
/**************************************************************************
*
* Function: UpdatePrinterOption
*
* Description: Reads the printer options type-in on the PrintBox UI
* and compares it to the specified printer option string. If
* the two differ, the printer option structure is updated to reflect
* the UI and is marked as modified.
*
* Parameters:
* pb (I) - this widget
* option_ptr (I) - printer options structure
*
* Return: none
*
**************************************************************************/
static void UpdatePrinterOption(PuiPrintBoxWidget pb,
PuiPrinterOption *option_ptr)
{
XtArgVal val;
/*
* Get the printer specific options string from the UI
*/
SynthGetOptionPrinterSpecific((Widget)pb, offset(printBox.res_spec_opts),
&val);
/*
* Compare the option strings and update if necessary
*/
if (strcmp((char*)val, option_ptr->option_str)) {
XtFree(option_ptr->option_str);
option_ptr->option_str = XtNewString((char*)val);
option_ptr->modified = True;
}
/*
* Clean up
*/
XtFree((char*)val);
}
/**************************************************************************
*
* Function: InitCallback
*
* Description: Initializes a callback structure. All fields of the
* callback structure are set to default values. This way the caller
* need only set the fields of interest after calling this function.
*
* Parameters:
* cb (I) - pointer to a callback struct
*
* Return: none
*
**************************************************************************/
static void InitCallback(PuiPrintBoxCallbackStruct *cb)
{
cb->reason = PuiCR_NOREASON;
cb->event = NULL;
cb->job_info = NULL;
cb->selected_printer = NULL;
cb->selected_position = 0;
cb->error_code = 0;
}
/*
==========================================================================
SYNTHETIC RESOURCE FUNCTIONS
==========================================================================
*/
/**************************************************************************
*
* Function: SynthGetFilename
*
* Description: Synthetic resource function for getting the filename value
* from the UI.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetFilename(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
*valuep = (XtArgVal)XmTextFieldGetString(pbp->files_widget);
}
/**************************************************************************
*
* Function: SynthGetPrinter
*
* Description: Synthetic resource function for getting the selected
* printer from the UI.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetPrinter(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
if (pbp->res_printer) {
XtFree((char*)pbp->res_printer);
pbp->res_printer = NULL;
}
if (pbp->selected_printer_index >= 0)
pbp->res_printer =
XtNewString(
pbp->res_printer_list[pbp->selected_printer_index].local_name);
*valuep = (XtArgVal)pbp->res_printer;
}
/**************************************************************************
*
* Function: SynthGetButtonSpacing
*
* Description: Synthetic resource function for getting the action area
* button spacing from the row column.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetButtonSpacing(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
Dimension spacing;
Arg arg;
XtSetArg(arg, XmNspacing, &spacing);
XtGetValues(pbp->action_rc, &arg, 1);
*valuep = (XtArgVal)spacing;
}
/**************************************************************************
*
* Function: SynthGetVisibleCount
*
* Description: Synthetic resource function for getting the visible item
* count from the printer list.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetVisibleCount(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
Arg arg;
XtSetArg(arg, XmNvisibleItemCount, valuep);
XtGetValues(pbp->plist_widget, &arg, 1);
}
/**************************************************************************
*
* Function: SynthGetLabel
*
* Description: Synthetic resource function for getting the labels
* of various UI child components directly from the component.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
static void SynthGetLabel(Widget w, int resource_offset, XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
String res_name = XmNlabelString;
Widget label_widget;
/*
* Based on the resource querried get the appropriate label
* widget
*/
switch (resource_offset) {
case offset(printBox.res_printb_label):
label_widget = pbp->printb_widget;
break;
case offset(printBox.res_user1b_label):
label_widget = pbp->user1b_widget;
break;
case offset(printBox.res_user2b_label):
label_widget = pbp->user2b_widget;
break;
case offset(printBox.res_user3b_label):
label_widget = pbp->user3b_widget;
break;
case offset(printBox.res_user4b_label):
label_widget = pbp->user4b_widget;
break;
case offset(printBox.res_optionsb_label):
label_widget = pbp->optionsb_widget;
break;
case offset(printBox.res_saveb_label):
label_widget = pbp->saveb_widget;
break;
case offset(printBox.res_cancelb_label):
label_widget = pbp->cancelb_widget;
break;
case offset(printBox.res_helpb_label):
label_widget = pbp->helpb_widget;
break;
case offset(printBox.res_files_label):
label_widget = pbp->files_label_widget;
break;
case offset(printBox.res_plist_label):
label_widget = pbp->plist_label_widget;
break;
case offset(printBox.res_opts_label):
label_widget = pbp->opts_label_widget;
break;
case offset(printBox.res_numcopies_label):
label_widget = pbp->numcopies_label_widget;
break;
case offset(printBox.res_title_label):
label_widget = pbp->title_label_widget;
break;
case offset(printBox.res_deftitle_label):
label_widget = pbp->banner_deftitle_widget;
break;
case offset(printBox.res_spectitle_label):
label_widget = pbp->banner_spectitle_widget;
break;
case offset(printBox.res_complete_label):
label_widget = pbp->complete_label_widget;
break;
case offset(printBox.res_complete_mail_label):
label_widget = pbp->complete_mail_widget;
break;
case offset(printBox.res_complete_mess_label):
label_widget = pbp->complete_mess_widget;
break;
case offset(printBox.res_handling_label):
label_widget = pbp->handling_label_widget;
break;
case offset(printBox.res_handling_copy_label):
label_widget = pbp->handling_copy_widget;
break;
case offset(printBox.res_handling_link_label):
label_widget = pbp->handling_link_widget;
break;
case offset(printBox.res_spec_options_label):
label_widget = pbp->spec_options_label_widget;
break;
case offset(printBox.res_savedlg_title_label):
label_widget = pbp->save_dialog_widget;
res_name = XmNdialogTitle;
break;
case offset(printBox.res_savedlg_saveb_label):
label_widget = pbp->save_dialog_widget;
res_name = XmNokLabelString;
break;
case offset(printBox.res_savedlg_userb_label):
label_widget = pbp->save_dialog_widget;
res_name = XmNokLabelString;
break;
case offset(printBox.res_savedlg_allb_label):
label_widget = pbp->save_dialog_widget;
res_name = XmNcancelLabelString;
break;
case offset(printBox.res_savedlg_cancelb_label):
label_widget = pbp->save_dialog_widget;
res_name = XmNhelpLabelString;
break;
case offset(printBox.res_savedlg_msg_label):
label_widget = pbp->save_msg_widget;
break;
default:
label_widget = NULL;
break;
}
/*
* Get the widget label string
*/
if (label_widget) {
Arg arg;
XtSetArg(arg, res_name, valuep);
XtGetValues(label_widget, &arg, 1);
} else
*valuep = NULL;
}
/*
==========================================================================
PRINTING OPTION FUNCTIONS
==========================================================================
*/
/*
--------------------------------------------------------------------------
Number Of Copies
--------------------------------------------------------------------------
*/
static void option_numcopies_val_cb(Widget, XtPointer, XtPointer);
static void option_numcopies_ud_cb(Widget, XtPointer, XtPointer);
/**************************************************************************
*
* Function: CreateOptionNumCopies
*
* Description: Create the number of copies option components
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
static void CreateOptionNumCopies(PuiPrintBoxPart *pbp, Widget parent)
{
Widget rc, inc_widget, dec_widget;
DEFARGS(15);
/*
* Create a horixontal RowColumn to hold the label and
* text field
*/
STARTARGS;
SETARG(XmNorientation, XmHORIZONTAL);
SETARG(XmNpacking, XmPACK_TIGHT);
SETARG(XmNspacing, LABEL_FIELD_SPACE);
rc = XtCreateWidget("numCopiesRowC", xmRowColumnWidgetClass,
parent, ARGLIST);
if (pbp->res_show_numcopies)
XtManageChild(rc);
/*
* Create the field label
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_numcopies_label);
pbp->numcopies_label_widget = XtCreateManagedWidget(DEF_NUMCOPIES_LABEL,
xmLabelWidgetClass,
rc, ARGLIST);
/*
* Create the field
*/
STARTARGS;
SETARG(XmNcolumns, NUM_COPIES_COLS);
SETARG(XmNmarginHeight, TEXT_FIELD_MAR);
SETARG(XmNmarginWidth, TEXT_FIELD_MAR);
pbp->numcopies_text_widget = XtCreateManagedWidget("numCopiesText",
xmTextFieldWidgetClass,
rc, ARGLIST);
/*
* Create the increment and decrement buttons
*/
STARTARGS;
SETARG(XmNwidth, ARROW_WIDTH);
SETARG(XmNuserData, (XtPointer)1);
SETARG(XmNarrowDirection, XmARROW_UP);
inc_widget = XtCreateManagedWidget("incButton",
xmArrowButtonWidgetClass,
rc, ARGLIST);
STARTARGS;
SETARG(XmNwidth, ARROW_WIDTH);
SETARG(XmNuserData, (XtPointer)-1);
SETARG(XmNarrowDirection, XmARROW_DOWN);
dec_widget = XtCreateManagedWidget("decButton",
xmArrowButtonWidgetClass,
rc, ARGLIST);
/*
* Register the text field modify callback
*/
XtAddCallback(pbp->numcopies_text_widget, XmNmodifyVerifyCallback,
option_numcopies_val_cb, (XtPointer)pbp);
/*
* Register the increment/decrement button callbacks
*/
XtAddCallback(inc_widget, XmNactivateCallback, option_numcopies_ud_cb,
(XtPointer)pbp);
XtAddCallback(dec_widget, XmNactivateCallback, option_numcopies_ud_cb,
(XtPointer)pbp);
}
/**************************************************************************
*
* Function: SetOptionNumCopies
*
* Description: Sets the number of copies option based on the resource
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetOptionNumCopies(PuiPrintBoxPart *pbp)
{
char buf[50];
(void)sprintf(buf, "%d", pbp->res_numcopies);
XmTextFieldSetString(pbp->numcopies_text_widget, buf);
}
/**************************************************************************
*
* Function: GetOptionNumCopies
*
* Description: Gets the print parameter for the number of copies option
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void GetOptionNumCopies(PuiPrintBoxPart *pbp)
{
char *str;
str = XmTextFieldGetString(pbp->numcopies_text_widget);
if ((pbp->num_copies = atoi(str)) <= 0) {
pbp->num_copies = 1;
XmTextFieldSetString(pbp->numcopies_text_widget, "1");
}
XtFree((char*)str);
}
/**************************************************************************
*
* Function: SynthGetOptionNumCopies
*
* Description: Updates the number of copies resource based on the state of
* the UI.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetOptionNumCopies(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
char *str;
int num;
str = XmTextFieldGetString(pbp->numcopies_text_widget);
if ((num = atoi(str)) <= 0) {
num = 1;
XmTextFieldSetString(pbp->numcopies_text_widget, "1");
}
XtFree((char*)str);
*valuep = (XtArgVal)num;
}
/**************************************************************************
*
* Function: option_numcopies_val_cb
*
* Description: Called whenever the number of copies text field value is
* modified. This routine only allows decimal digits to be typed
* into the text field.
*
* Parameters:
* w (I) - widget that invoked callback
* client_data (I) - this widget's instance part
* call_data (I) - text field verify callback struct
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void option_numcopies_val_cb(Widget w, XtPointer client_data,
XtPointer call_data)
{
int i;
XmTextVerifyCallbackStruct *cb = (XmTextVerifyCallbackStruct*)call_data;
cb->doit = True;
if (cb->text->ptr == NULL || cb->text->length == 0) {
cb->text->ptr = XtNewString("");
return;
}
for (i = 0; i < cb->text->length; i++) {
if (!isdigit((int)cb->text->ptr[i])) {
cb->doit = False;
break;
}
}
}
/**************************************************************************
*
* Function: option_numcopies_ud_cb
*
* Description: Called whenever the increment or decrement buttons are
* activated. The buttons increment or decrement the value in the
* number of copies text field.
*
* Parameters:
* w (I) - widget that invoked callback
* client_data (I) - this widget's instance part
* call_data (I) - not used
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void option_numcopies_ud_cb(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxPart *pbp = (PuiPrintBoxPart*)client_data;
char *str, buf[NUM_COPIES_COLS + 5];
int direction, num;
DEFARGS(5);
/*
* Get the button direction - add or subtract
*/
STARTARGS;
SETARG(XmNuserData, &direction);
XtGetValues(w, ARGLIST);
/*
* Change the text field value if appropriate
*/
str = XmTextFieldGetString(pbp->numcopies_text_widget);
if ((num = atoi(str) + direction) <= 0)
num = 1;
XtFree((char*)str);
(void)sprintf(buf, "%d", num);
XmTextFieldSetString(pbp->numcopies_text_widget, buf);
}
/*
--------------------------------------------------------------------------
Banner Page
--------------------------------------------------------------------------
*/
static void option_banner_text_cb(Widget, XtPointer, XtPointer);
/**************************************************************************
*
* Function: CreateOptionBanner
*
* Description: Create the banner page options
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
static void CreateOptionBanner(PuiPrintBoxPart *pbp, Widget parent)
{
Widget rc, bb;
DEFARGS(15);
/*
* Create a vertical RowColumn to hold everything
*/
STARTARGS;
SETARG(XmNorientation, XmVERTICAL);
SETARG(XmNpacking, XmPACK_TIGHT);
rc = XtCreateWidget("bannerRowC", xmRowColumnWidgetClass,
parent, ARGLIST);
if (pbp->res_show_bannertitle)
XtManageChild(rc);
/*
* Create the banner page printing button
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_title_label);
pbp->title_label_widget = XtCreateManagedWidget(DEF_JOBTITLE_LABEL,
xmLabelWidgetClass, rc, ARGLIST);
/*
* Create the title selection buttons
*/
STARTARGS;
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
bb = XtCreateManagedWidget("bannerRadioBB", xmBulletinBoardWidgetClass,
rc, ARGLIST);
STARTARGS;
SETARG(XmNx, OPTS_INDENT);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
SETARG(XmNspacing, 0);
pbp->banner_select_widget = XmCreateRadioBox(bb, "bannerRadio", ARGLIST);
XtManageChild(pbp->banner_select_widget);
STARTARGS;
SETARG(XmNlabelString, pbp->res_deftitle_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->banner_deftitle_widget = XtCreateManagedWidget(DEF_DEFTITLE_LABEL,
xmToggleButtonWidgetClass,
pbp->banner_select_widget, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_spectitle_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->banner_spectitle_widget = XtCreateManagedWidget(DEF_SPECTITLE_LABEL,
xmToggleButtonWidgetClass,
pbp->banner_select_widget, ARGLIST);
/*
* Create the title specification text field
*/
STARTARGS;
SETARG(XmNx, OPTS_INDENT + WIDTH(pbp->banner_spectitle_widget) +
LABEL_FIELD_SPACE);
SETARG(XmNy, HEIGHT(pbp->banner_spectitle_widget));
SETARG(XmNcolumns, JOB_TITLE_COLS);
SETARG(XmNmarginHeight, TEXT_FIELD_MAR);
SETARG(XmNmarginWidth, TEXT_FIELD_MAR);
pbp->banner_text_widget = XtCreateManagedWidget("bannerText",
xmTextFieldWidgetClass,
bb, ARGLIST);
/*
* Register the text field modify callback
*/
XtAddCallback(pbp->banner_text_widget, XmNvalueChangedCallback,
option_banner_text_cb, (XtPointer)pbp);
}
/**************************************************************************
*
* Function: SetOptionBanner
*
* Description: Sets the banner page option based on the resource
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void SetOptionBanner(PuiPrintBoxPart *pbp)
{
if (pbp->res_job_title)
XmTextFieldSetString(pbp->banner_text_widget, pbp->res_job_title);
else {
XmToggleButtonSetState(pbp->banner_deftitle_widget, True, True);
XmToggleButtonSetState(pbp->banner_spectitle_widget, False, True);
}
}
/**************************************************************************
*
* Function: GetOptionBanner
*
* Description: Gets the print parameter for the banner page option
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
static void GetOptionBanner(PuiPrintBoxPart *pbp)
{
char *str;
/*
* Clear any previous title
*/
if (pbp->job_title) {
free((char*)pbp->job_title);
pbp->job_title = NULL;
}
/*
* Return banner page title if one has been specified
*/
if (!XmToggleButtonGetState(pbp->banner_deftitle_widget)) {
str = XmTextFieldGetString(pbp->banner_text_widget);
pbp->job_title = strdup(str);
XtFree((char*)str);
}
}
/**************************************************************************
*
* Function: SynthGetOptionBanner
*
* Description: Updates the banner page option resources based on the
* state of the UI.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetOptionBanner(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
/*
* Get banner page title
*/
if (!XmToggleButtonGetState(pbp->banner_deftitle_widget))
*valuep = (XtArgVal)XmTextFieldGetString(pbp->banner_text_widget);
else
*valuep = (XtArgVal)NULL;
}
/**************************************************************************
*
* Function: option_banner_text_cb
*
* Description: Callback for setting the title selection toggle buttons
* to user specified title when the title text field is typed-in.
* The object here is that when a user types in the banner page title
* text field, we can assume that they want this title printed on
* the banner page. Therefore, let's help the user and set the toggle
* buttons to select the user specified title automatically when
* he types in the text field.
*
* Parameters:
* w (I) - widget that invoked callback
* client_data (I) - this widget's instance part
* call_data (I) - toggle button callback struct
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void option_banner_text_cb(Widget w, XtPointer client_data,
XtPointer call_data)
{
PuiPrintBoxPart *pbp = (PuiPrintBoxPart*)client_data;
XmToggleButtonSetState(pbp->banner_deftitle_widget, False, True);
XmToggleButtonSetState(pbp->banner_spectitle_widget, True, True);
}
/*
--------------------------------------------------------------------------
Job Completion Notification
--------------------------------------------------------------------------
*/
/**************************************************************************
*
* Function: CreateOptionCompletion
*
* Description: Create the job completion notification option
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void CreateOptionCompletion(PuiPrintBoxPart *pbp, Widget parent)
{
Widget widget, rc, bb;
DEFARGS(15);
/*
* Create a vertical RowColumn to put everything in
*/
STARTARGS;
SETARG(XmNorientation, XmVERTICAL);
SETARG(XmNpacking, XmPACK_TIGHT);
rc = XtCreateWidget("completeRowC", xmRowColumnWidgetClass,
parent, ARGLIST);
if (pbp->res_show_completion)
XtManageChild(rc);
/*
* Create the job completion notification button
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_complete_label);
pbp->complete_label_widget = XtCreateManagedWidget(DEF_COMPLETION_LABEL,
xmLabelWidgetClass,
rc, ARGLIST);
/*
* Create the notification selection buttons
*/
STARTARGS;
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
bb = XtCreateManagedWidget("completeCheckBB", xmBulletinBoardWidgetClass,
rc, ARGLIST);
STARTARGS;
SETARG(XmNx, OPTS_INDENT);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
SETARG(XmNspacing, 0);
widget = XmCreateRadioBox(bb, "completeCheck", ARGLIST);
XtManageChild(widget);
STARTARGS;
SETARG(XmNradioBehavior, False);
SETARG(XmNindicatorType, XmN_OF_MANY);
XtSetValues(widget, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_complete_mail_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->complete_mail_widget = XtCreateManagedWidget(DEF_MAIL_LABEL,
xmToggleButtonWidgetClass,
widget, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_complete_mess_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->complete_mess_widget = XtCreateManagedWidget(DEF_MESSAGE_LABEL,
xmToggleButtonWidgetClass,
widget, ARGLIST);
}
/**************************************************************************
*
* Function: SetOptionCompletion
*
* Description: Sets the job completion option based on the resource
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SetOptionCompletion(PuiPrintBoxPart *pbp)
{
XmToggleButtonSetState(pbp->complete_mail_widget, pbp->res_mail, True);
XmToggleButtonSetState(pbp->complete_mess_widget, pbp->res_message, True);
}
/**************************************************************************
*
* Function: GetOptionCompletion
*
* Description: Gets the completion parameter for the job completion
* option
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void GetOptionCompletion(PuiPrintBoxPart *pbp)
{
if (XmToggleButtonGetState(pbp->complete_mail_widget))
pbp->mail = 1;
else
pbp->mail = 0;
if (XmToggleButtonGetState(pbp->complete_mess_widget))
AddPrinterOptions(pbp, "-w");
}
/**************************************************************************
*
* Function: SynthGetOptionCompletion
*
* Description: Updates the completion resource based on the state of the UI
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetOptionCompletion(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
if (resource_offset == offset(printBox.res_mail)) {
if (XmToggleButtonGetState(pbp->complete_mail_widget))
*valuep = (XtArgVal)True;
else
*valuep = (XtArgVal)False;
} else {
if (XmToggleButtonGetState(pbp->complete_mess_widget))
*valuep = (XtArgVal)True;
else
*valuep = (XtArgVal)False;
}
}
/*
--------------------------------------------------------------------------
Print File Handling
--------------------------------------------------------------------------
*/
/**************************************************************************
*
* Function: CreateOptionJobHandling
*
* Description: Create the print file handling option
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void CreateOptionJobHandling(PuiPrintBoxPart *pbp, Widget parent)
{
Widget widget, rc, bb;
DEFARGS(15);
/*
* Create a vertical RowColumn to put everything in
*/
STARTARGS;
SETARG(XmNorientation, XmVERTICAL);
SETARG(XmNpacking, XmPACK_TIGHT);
rc = XtCreateWidget("handlingRowC", xmRowColumnWidgetClass,
parent, ARGLIST);
if (pbp->res_show_handling)
XtManageChild(rc);
/*
* Create the file handling label
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_handling_label);
pbp->handling_label_widget = XtCreateManagedWidget(DEF_HANDLING_LABEL,
xmLabelWidgetClass,
rc, ARGLIST);
/*
* Create the file handling method buttons
*/
STARTARGS;
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
bb = XtCreateManagedWidget("completeCheckBB", xmBulletinBoardWidgetClass,
rc, ARGLIST);
STARTARGS;
SETARG(XmNx, OPTS_INDENT);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
SETARG(XmNspacing, 0);
widget = XmCreateRadioBox(bb, "handlingRadio", ARGLIST);
XtManageChild(widget);
STARTARGS;
SETARG(XmNlabelString, pbp->res_handling_link_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->handling_link_widget = XtCreateManagedWidget(DEF_LINK_LABEL,
xmToggleButtonWidgetClass,
widget, ARGLIST);
STARTARGS;
SETARG(XmNlabelString, pbp->res_handling_copy_label);
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
pbp->handling_copy_widget = XtCreateManagedWidget(DEF_COPY_LABEL,
xmToggleButtonWidgetClass,
widget, ARGLIST);
}
/**************************************************************************
*
* Function: SetOptionJobHandling
*
* Description: Sets the print file handling option based on the resource
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SetOptionJobHandling(PuiPrintBoxPart *pbp)
{
if (pbp->res_copy) {
XmToggleButtonSetState(pbp->handling_link_widget, False, True);
XmToggleButtonSetState(pbp->handling_copy_widget, True, True);
} else {
XmToggleButtonSetState(pbp->handling_link_widget, True, True);
XmToggleButtonSetState(pbp->handling_copy_widget, False, True);
}
}
/**************************************************************************
*
* Function: GetOptionJobHandling
*
* Description: Gets the handling parameter for the print file handling
* option
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void GetOptionJobHandling(PuiPrintBoxPart *pbp)
{
if (XmToggleButtonGetState(pbp->handling_link_widget))
pbp->copy_file = 0;
else
pbp->copy_file = 1;
}
/**************************************************************************
*
* Function: SynthGetOptionJobHandling
*
* Description: Updates the handling resources based on the state of the
* UI
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetOptionJobHandling(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
if (XmToggleButtonGetState(pbp->handling_link_widget))
*valuep = (XtArgVal)False;
else
*valuep = (XtArgVal)True;
}
/*
--------------------------------------------------------------------------
Printer Specific Options
--------------------------------------------------------------------------
*/
/**************************************************************************
*
* Function: CreateOptionPrinterSpecific
*
* Description: Create the printer specific options type in field
*
* Parameters:
* pbp (I) - this widget's instance part
* parent (I) - parent widget ID
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void CreateOptionPrinterSpecific(PuiPrintBoxPart *pbp, Widget parent)
{
Widget rc, bb;
DEFARGS(15);
/*
* Create a vertical RowColumn to put everything in
*/
STARTARGS;
SETARG(XmNorientation, XmVERTICAL);
SETARG(XmNpacking, XmPACK_TIGHT);
rc = XtCreateWidget("specOptionsRowC", xmRowColumnWidgetClass,
parent, ARGLIST);
if (pbp->res_show_printeroptions)
XtManageChild(rc);
/*
* Create the label
*/
STARTARGS;
SETARG(XmNlabelString, pbp->res_spec_options_label);
pbp->spec_options_label_widget = XtCreateManagedWidget(
DEF_PRINTERSPEC_LABEL,
xmLabelWidgetClass,
rc, ARGLIST);
/*
* Create the printer specific ooptions text entry field
*/
STARTARGS;
SETARG(XmNmarginHeight, 0);
SETARG(XmNmarginWidth, 0);
bb = XtCreateManagedWidget("specOptionsBB", xmBulletinBoardWidgetClass,
rc, ARGLIST);
STARTARGS;
SETARG(XmNx, OPTS_INDENT);
SETARG(XmNcolumns, SPEC_OPTS_COLS);
SETARG(XmNmarginHeight, TEXT_FIELD_MAR);
SETARG(XmNmarginWidth, TEXT_FIELD_MAR);
pbp->spec_options_widget = XtCreateManagedWidget("specOptionsText",
xmTextFieldWidgetClass,
bb, ARGLIST);
}
/**************************************************************************
*
* Function: SetOptionPrinterSpecific
*
* Description: Sets the printer specific option based on the resource
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SetOptionPrinterSpecific(PuiPrintBoxPart *pbp)
{
if (pbp->res_spec_opts)
XmTextFieldSetString(pbp->spec_options_widget, pbp->res_spec_opts);
else
XmTextFieldSetString(pbp->spec_options_widget, "");
}
/**************************************************************************
*
* Function: GetOptionPrinterSpecific
*
* Description: Gets the print parameters for the printer specific
* options
*
* Parameters:
* pbp (I) - this widget's instance part
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void GetOptionPrinterSpecific(PuiPrintBoxPart *pbp)
{
char *str, *opt;
str = XmTextFieldGetString(pbp->spec_options_widget);
if (str && *str) {
opt = (char*)malloc(strlen(str) + 10);
(void)sprintf(opt, "-o\"%s\"", str);
AddPrinterOptions(pbp, opt);
free((char*)opt);
}
XtFree((char*)str);
}
/**************************************************************************
*
* Function: SynthGetOptionPrinterSpecific
*
* Description: Updates the printer specific parameter resource based on
* the state of the UI.
*
* Parameters:
* w (I) - this widget
* resource_offset (I) - offset of value in instance part
* valuep (O) - value to return
*
* Return: none
*
**************************************************************************/
/* ARGSUSED */
static void SynthGetOptionPrinterSpecific(Widget w, int resource_offset,
XtArgVal *valuep)
{
PuiPrintBoxPart *pbp = &((PuiPrintBoxWidget)w)->printBox;
*valuep = (XtArgVal)XmTextFieldGetString(pbp->spec_options_widget);
}
/*
==========================================================================
PUBLIC AND CONVENIENCE FUNCTIONS
==========================================================================
*/
/**************************************************************************
*
* Function: PuiCreatePrintBox
*
* Description: Creates an unmanaged PrintBox widget.
*
* Parameters:
* parent (I) - parent widget ID
* name (I) - instance name for newly created widget
* args (I) - widget resource settings
* num (I) - number of resources specified.
*
* Return: Widget ID of newly created PrintBox widget.
*
**************************************************************************/
Widget PuiCreatePrintBox(Widget parent, String name, ArgList args,
Cardinal num)
{
return XtCreateWidget(name, puiPrintBoxWidgetClass, parent, args, num);
}
/**************************************************************************
*
* Function: PuiCreatePrintDialog
*
* Description: Creates an unmanaged Dialog Shell and a widget as a child
* of that shell.
*
* Parameters:
* parent (I) - parent widget ID
* name (I) - instance name for newly created PrintBox widget
* args (I) - widget resource settings
* num (I) - number of resources specified.
*
* Return: Widget ID of newly created PrintBox widget.
*
**************************************************************************/
Widget PuiCreatePrintDialog(Widget parent, String name, ArgList args,
Cardinal num)
{
Widget ds, pb;
ArgList ds_args, pb_args;
char *ds_name;
/*
* Create the DialogShell parent
*/
ds_name = XtCalloc(strlen(name)+XmDIALOG_SUFFIX_SIZE+1, sizeof(char));
(void)sprintf(ds_name, "%s%s", name, XmDIALOG_SUFFIX);
ds_args = (ArgList)XtMalloc(sizeof(Arg) * (num + 1));
(void)memcpy(ds_args, args, sizeof(Arg) * num);
XtSetArg(ds_args[num], XmNallowShellResize, True);
ds = XtCreatePopupShell(ds_name, xmDialogShellWidgetClass, parent,
ds_args, num + 1);
XtFree((char*)ds_args);
XtFree(ds_name);
/*
* Allocate arglist, copy args
*/
pb_args = (ArgList)XtMalloc(sizeof(Arg) * num);
(void)memcpy(pb_args, args, sizeof(Arg) * num);
/*
* Create PrintBox, free args, return
*/
pb = XtCreateWidget(name, puiPrintBoxWidgetClass, ds, pb_args, num);
XtAddCallback(pb, XmNdestroyCallback, DestroyParentCB, NULL);
XtFree((char*)pb_args);
return (pb);
}
/**************************************************************************
*
* Function: PuiPrintBoxGetChild
*
* Description: Returns the widget ID of the specified PrintBox child
* widget.
*
* Parameters:
* w (I) - printBox widget whose child to get
* child (I) - token specifying child whose ID to return.
*
* Return: Widget ID of the specified child.
*
**************************************************************************/
Widget PuiPrintBoxGetChild(Widget w, int child)
{
PuiPrintBoxPart *pbp = &(((PuiPrintBoxWidget)w)->printBox);
Widget widget = (Widget)NULL;
switch (child) {
case PuiPRINTBOX_PRINT_BUTTON:
widget = pbp->printb_widget;
break;
case PuiPRINTBOX_USER1_BUTTON:
widget = pbp->user1b_widget;
break;
case PuiPRINTBOX_USER2_BUTTON:
widget = pbp->user2b_widget;
break;
case PuiPRINTBOX_USER3_BUTTON:
widget = pbp->user3b_widget;
break;
case PuiPRINTBOX_USER4_BUTTON:
widget = pbp->user4b_widget;
break;
case PuiPRINTBOX_OPTIONS_BUTTON:
widget = pbp->optionsb_widget;
break;
case PuiPRINTBOX_SAVE_BUTTON:
widget = pbp->saveb_widget;
break;
case PuiPRINTBOX_CANCEL_BUTTON:
widget = pbp->cancelb_widget;
break;
case PuiPRINTBOX_HELP_BUTTON:
widget = pbp->helpb_widget;
break;
case PuiPRINTBOX_WORK_AREA:
widget = pbp->work_area;
break;
case PuiPRINTBOX_SEPARATOR:
widget = pbp->separator;
break;
default:
XtWarning(gettxt(_SGI_LIBPRINTUI_BADCHILD,
"PuiPrintBoxGetChild - invalid child token"));
break;
}
return widget;
}
/**************************************************************************
*
* Function: PuiPrintBoxDoPrint
*
* Description: Convenience function that calls the callback functions on
* the print button callback list. This function simulates the
* pressing of the Print button on the printBox widget action area.
*
* Note that the callbacks for the print button will be called with
* the event field of the callback structure set to NULL.
*
* Parameters:
* w (I) - printBox widget instance ID
*
* Return: none
*
**************************************************************************/
void PuiPrintBoxDoPrint(Widget w)
{
PuiPrintBoxPart *pbp = &(((PuiPrintBoxWidget)w)->printBox);
XmPushButtonCallbackStruct cb;
cb.reason = XmCR_ACTIVATE;
cb.event = NULL;
cb.click_count = 1;
XtCallCallbacks(pbp->printb_widget, XmNactivateCallback, (XtPointer)&cb);
}
/**************************************************************************
*
* Function: PuiCvtStringToPrintingPolicy
*
* Description: Converter for resource type PuiRPrintingPolicy
*
* Parameters:
* disp (I) - X connection
* args (I) - arguments to converter
* num_argsp (I) - number of arguments to converter
* from_val (I) - value to convert from
* to_val (O) - converted value
* conv_data (O) - converter specific data
*
* Return: True if conversion successful and False if conversion not
* successful or too little storage available to store conversion
* result.
*
**************************************************************************/
/* ARGSUSED */
Boolean PuiCvtStringToPrintingPolicy(Display *disp, XrmValuePtr args,
Cardinal *num_argsp, XrmValuePtr from_val, XrmValuePtr to_val,
XtPointer *conv_data)
{
int policy;
/*
* This converter does not use any arguments
*/
if (*num_argsp != 0)
XtWarning(gettxt(_SGI_LIBPRINTUI_POLICYNOARGS,
"PuiCvtStringToPrintingPolicy - no arguments needed"));
/*
* Determine the printing policy token by comparing the resource
* strings (could be done with quarks but not a big deal)
*/
if (!strcmp((char*)from_val->addr, PuiWIDGET_PRINTING_STR))
policy = PuiWIDGET_PRINTING;
else if (!strcmp((char*)from_val->addr, PuiAPPLICATION_PRINTING_STR))
policy = PuiAPPLICATION_PRINTING;
else {
XtDisplayStringConversionWarning(disp, (char*)from_val->addr,
PuiRPrintingPolicy);
return False;
}
/*
* Send the policy value back to the caller. If space has been
* allocated, pass the value. Otherwise pass pointer to our
* static storage for the value
*/
if (to_val->addr) {
if (to_val->size < sizeof(int)) {
to_val->size = sizeof(int);
return False;
}
*(int*)(to_val->addr) = policy;
} else {
static int stat_policy;
stat_policy = policy;
to_val->addr = (XtPointer)&stat_policy;
}
to_val->size = sizeof(int);
return True;
}
/**************************************************************************
*
* Function: PuiCvtStringToButtonPlacement
*
* Description: Converter for resource type PuiRButtonPlacement
*
* Parameters:
* disp (I) - X connection
* args (I) - arguments to converter
* num_argsp (I) - number of arguments to converter
* from_val (I) - value to convert from
* to_val (O) - converted value
* conv_data (O) - converter specific data
*
* Return: True if conversion successful and False if conversion not
* successful or too little storage available to store conversion
* result.
*
**************************************************************************/
/* ARGSUSED */
Boolean PuiCvtStringToButtonPlacement(Display *disp, XrmValuePtr args,
Cardinal *num_argsp, XrmValuePtr from_val, XrmValuePtr to_val,
XtPointer *conv_data)
{
int placement;
/*
* This converter does not use any arguments
*/
if (*num_argsp != 0)
XtWarning(gettxt(_SGI_LIBPRINTUI_BUTTONNOARGS,
"PuiCvtStringToButtonPlacement - no arguments needed"));
/*
* Determine the button palcement by comparing the resource
* strings (could be done with quarks but not a big deal)
*/
if (!strcmp((char*)from_val->addr, PuiBUTTONS_LEFT_STR))
placement = PuiBUTTONS_LEFT;
else if (!strcmp((char*)from_val->addr, PuiBUTTONS_RIGHT_STR))
placement = PuiBUTTONS_RIGHT;
else if (!strcmp((char*)from_val->addr, PuiBUTTONS_CENTER_STR))
placement = PuiBUTTONS_CENTER;
else {
XtDisplayStringConversionWarning(disp, (char*)from_val->addr,
PuiRButtonPlacement);
return False;
}
/*
* Send the placement value back to the caller. If space has been
* allocated, pass the value. Otherwise pass pointer to our
* static storage for the value
*/
if (to_val->addr) {
if (to_val->size < sizeof(int)) {
to_val->size = sizeof(int);
return False;
}
*(int*)(to_val->addr) = placement;
} else {
static int stat_placement;
stat_placement = placement;
to_val->addr = (XtPointer)&stat_placement;
}
to_val->size = sizeof(int);
return True;
}